0
import Yesod
import Data.Text

data App = App

instance Yesod App

mkYesod "App" [parseRoutes|
               / Home GET
               |]

getHome :: String -> Handler Value
getHome  =  object ["name" .= ("Adam"::Text)]

main = warpDebug 2012 App

抛出错误,

 Couldn't match expected type ‘String -> Handler Value’
                with actual type ‘Value’
    Possible cause: ‘object’ is applied to too many arguments
    In the expression: object ["name" .= ("Adam" :: Text)]
    In an equation for ‘getHome’:
        getHome = object ["name" .= ("Adam" :: Text)]

object不在前奏范围内。哪个包/模块定义了这个?为什么在上述情况下不取键值对?

4

1 回答 1

2

object不在前奏范围内。哪个包/模块定义了这个?

Yesod.Json

为什么在上述情况下不取键值对?

它需要键值对就好了。错误消息告诉您,这object给了您 a Value,但您声明getHome为 type String -> Handler Value,而不是Value

在这种情况下,“可能的原因”似乎只是具有误导性。

于 2015-05-07T08:00:50.143 回答