Skip to content

Instantly share code, notes, and snippets.

@cmoore
Created January 22, 2010 04:22
Show Gist options
  • Save cmoore/283507 to your computer and use it in GitHub Desktop.
Save cmoore/283507 to your computer and use it in GitHub Desktop.
{- Types.hs -}
{-# LANGUAGE DeriveDataTypeable #-}
module Brazil.Types where
import Data.Typeable ()
import Data.Generics
import Text.StringTemplate.GenericStandard ()
data LoggedInUser = LoggedInUser {
uid :: String,
name :: String,
origin :: String,
loggedin :: Bool
} deriving (Show,Data,Typeable)
{- Pages.hs -}
rpTemplate :: (ToSElem a) => Env -> String -> [(String,a)] -> [(String,String)] -> IO Response
rpTemplate env template args cookies' = do
group <- directoryGroup "templates"
ui <- user_info env -- user_info :: Env -> IO (Maybe [(String,String)]
cok <- case ui of
Just x -> do
let uui = fromJust $ lookup "uid" x
return [("uid", uui)]
Nothing -> do
uu <- uuid
return [("uid",(show uu))]
uif <- uinfo env -- uinfo :: Env -> IO (Maybe [(String,LoggedInUser)])
case uif of
Just y -> return $ def {
--- vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
body = pack $ renderTemplateGroup group (y ++ args :: [(String,LoggedInUser)]) template,
--- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
status = 200,
headers = (cookies' ++ cok) }
Nothing -> return $ def {
body = pack $ renderTemplateGroup group ([] :: [(String,LoggedInUser)]) template,
status = 200,
headers = (cookies' ++ cok) }
{-
Couldn't match expected type `LoggedInUser'
against inferred type `a'
`a' is a rigid type variable bound by
the type signature for `rpTemplate' at src/Brazil/Pages.hs:37:23
Expected type: [(String, LoggedInUser)]
Inferred type: [(String, a)]
In the second argument of `(++)', namely `args'
In the second argument of `renderTemplateGroup', namely
`((y :: [(String, LoggedInUser)]) ++ args)'
-}
{- Is my approach that far off or am I missing a LANGUAGE definition? -}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment