我对 Haskell 和 Snap 还很陌生,我正在为一个使用 snap 的小型网络论坛开发自己的项目。我遇到的问题是理解冲突以及如何解决以下代码。
handleCategoryAdd :: H ()
handleCategoryAdd = method POST (withLoggedInUser go)
where
go user = do
bs <- getParam "categoryName"
cN <- B.unpack $ Just bs
cD <- getParam "categoryDesc"
cT <- getCurrentTime
return (Db.saveCategory (Db.Category 1 cN cT "1" ))
redirect "/"
给我一个类型不匹配错误,如下所示:
src\Site.hs:118:22:
Couldn't match expected type `ByteString'
with actual type `Maybe ByteString'
In the first argument of `unpack', namely `bs'
In a stmt of a 'do' block: cN <- unpack bs
In the expression:
do { bs <- getParam "categoryName";
cN <- unpack bs;
cD <- getParam "categoryDesc";
cT <- getCurrentTime;
.... }
任何消除混淆的建议将不胜感激,我一直在寻找一些方法来解开可能并检索字节串,但没有成功。
非常感谢!