Created
January 22, 2010 04:22
-
-
Save cmoore/283507 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- 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