該應用類型類型錯誤snaplet會話
data App = App
{ _heist :: Snaplet (Heist App)
, _session :: Snaplet SessionManager
}
初始化器
...
addRoutes [ ("/ss", companyHandler)
, ("", heistServe)
]
...
處理機
companyHandler :: Handler b v()
companyHandler = method GET getter <|> method POST setter
where
getter = do
value <- getFromSession "name"
writeText $ fromMaybe "nothing" value
setter = do
mname <- getParam "name"
setInSession "name" (convert mname)
getter
convert = T.pack . B.unpack . (fromMaybe "nothing")
heistServe
的具有類型Handler b (Heist b)()
鍵入e RROR:
src/Tutorial.hs:50:52:
Couldn't match type `v' with `SessionManager'
`v' is a rigid type variable bound by
the type signature for companyHandler :: Handler b v()
at src/Tutorial.hs:50:1
Expected type: Handler b v()
Actual type: Handler b SessionManager()
In the second argument of `method', namely `setter'
In the second argument of `(<|>)', namely `method POST setter'
它不起作用。 'sessionSession'$ setInSession'name'(convert mname):: Handler b SessionManager()',用於'setInSession :: Text - > Text - > Handler b SessionManager()' – wenlong
對不起,我沒有測試過代碼,我應該這樣做。看起來,會話API是以奇怪的方式構建的;你需要使用'withTop'而不是'withSession'。如果你使用Session。 withTop session $ ...',它會爲你做的是在完成之後提交會話。 – dflemstr
它編譯,但會話不會在請求之間共享。完整的代碼是[在這裏使用](https://gist.github.com/1471406/547b13d5603a12090df2d2ad3fb7fd124ce3619e)和[在這裏使用withSession和withTop](https://gist.github.com/1471406/082e20e0a217255d52d79a770bc3ebdf554d578c) – wenlong