Skip to content

Instantly share code, notes, and snippets.

@funrep
Last active December 22, 2015 22:09
Show Gist options
  • Save funrep/6537889 to your computer and use it in GitHub Desktop.
Save funrep/6537889 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
import Web.ClientSession
import Data.Text.Lazy (Text, toStrict, fromStrict)
import Data.Text.Lazy.Encoding (encodeUtf8, decodeUtf8)
import Data.ByteString (ByteString)
import Data.Monoid ((<>))
initCookies :: IO (Text -> ActionM ())
initCookies = do
key <- getDefaultKey
return $ setCookie key
where
setCookie k id = encryptIO k (encode id)
>>= (\x -> header "Set-Cookie" ("sid=" <> decode x <> ";"))
encode :: Text -> ByteString
encode = encodeUtf8 . toStrict
decode :: ByteString -> Text
decode = fromStrict . decodeUtf8
@funrep
Copy link
Author

funrep commented Sep 12, 2013

foo.hs:16:35:
Couldn't match expected type bytestring-0.10.0.2:Data.ByteString.Internal.ByteString' with actual typeByteString'
In the return type of a call of encode' In the second argument ofencryptIO', namely (encode id)' In the first argument of(>>=)', namely `encryptIO k (encode id)'

foo.hs:17:18:
Couldn't match type ActionM' withIO'
Expected type: IO ()
Actual type: ActionM ()
In the return type of a call of header' In the expression: header "Set-Cookie" ("sid=" <> decode x <> ";") In the second argument of(>>=)', namely
`(\ x -> header "Set-Cookie" ("sid=" <> decode x <> ";"))'

foo.hs:17:56:
Couldn't match expected type ByteString' with actual typebytestring-0.10.0.2:Data.ByteString.Internal.ByteString'
In the first argument of decode', namelyx'
In the first argument of (<>)', namelydecode x'
In the second argument of (<>)', namelydecode x <> ";"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment