Haskell 不能';t匹配预期类型‘;邮政’;实际类型为‘;路线应用程序&x2019;
我正在尝试使用函数Haskell 不能';t匹配预期类型‘;邮政’;实际类型为‘;路线应用程序&x2019;,haskell,yesod,yesod-test,Haskell,Yesod,Yesod Test,我正在尝试使用函数postBody postBody :: (Yesod site, RedirectUrl site url) => url -> ByteString -> YesodExample site () 从包裹里拿出来。文件上说它可以这样使用 import Data.Aeson postBody HomeR (encode $ object ["age" .= (1 :: Integer)]) 但是当我尝试在我的应用程序中使用它时 describe
postBody
postBody :: (Yesod site, RedirectUrl site url) => url -> ByteString -> YesodExample site ()
从包裹里拿出来。文件上说它可以这样使用
import Data.Aeson
postBody HomeR (encode $ object ["age" .= (1 :: Integer)])
但是当我尝试在我的应用程序中使用它时
describe "Posts" $ do
it "posts post and returns post" $ do
postBody PostR (encode $ object [
"body" .= ("test post" :: Text),
"title" .= ("test post" :: Text),
"coverImage" .= ("test post" :: Text),
"author" .= (0 :: Int)
])
statusIs 200
我弄错了
• Couldn't match expected type ‘Post’ with actual type ‘Route App’
• In the first argument of ‘postBody’, namely ‘PostR’
In a stmt of a 'do' block:
postBody
PostR
(encode
$ object
["body" .= ("test post" :: Text), "title" .= ("test post" :: Text),
"coverImage" .= ("test post" :: Text), "author" .= (0 :: Int)])
In the second argument of ‘($)’, namely
‘do { postBody
PostR
(encode
$ object
["body" .= ("test post" :: Text), "title" .= ("test post" :: Text),
....]);
statusIs 200 }’
我的用法似乎与示例相同,所以我看不出它为什么会失败
PostR在这里的routes文件中
/PostR POST
以及它的处理程序
postPostR :: Handler Value
postPostR = do
post <- requireJsonBody :: Handler Post
maybeUserID <- maybeAuthId
case maybeUserID of
Just userID -> do
let post' = post {postAuthor = userID}
inserted <- runDB $ insertEntity post'
returnJson inserted
Nothing -> sendResponseStatus status403 ("Unauthorized" :: Text)
pospostost::处理程序值
postostr=do
post sendResponseStatus 403(“未授权”::文本)
问题在于posts表中有一个列主体,因此Yesod为此创建了postBody,这与Yesod.Test中的postBody冲突
解决方案是使用合格的yesod测试导入
import qualified Yesod.Test as T
您的
PostR
是如何定义的?@FyodorSoikin被编辑以显示信息。