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

throws error as,

 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 is not in scope in prelude. Which package/module defines this? Why doesn't it take the key-value pair in the above case?

1 Answers1

2

object is not in scope in prelude. Which package/module defines this?

Yesod.Json

Why doesn't it take the key-value pair in the above case?

It takes the key value pair just fine. The error message is telling you that object gives you a Value, but you declared getHome to be of type String -> Handler Value, not Value.

The "possible cause" seems to just be misleading in this case.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
  • I tried changing the type. It gave this error - Couldn't match expected type ‘HandlerT App IO res0’ with actual type ‘Value’ . `getHome` is my HTTP GET handler that returns a json response. How can i wrap the `Value` type with `Handler` instead of changing the type? –  May 07 '15 at 09:44