Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is jsonToRepJson broken?

Tags:

haskell

yesod

I'm just starting doing some Yesod + Haskell stuff. Is jsonToRepJson broken or something?

I made this code below but I always get an error in jsonToRepJson part. It seems it doesn't get the expected type?

Any help would be great! Thanks :3

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
import Yesod
import Data.Text

data APP = APP

instance Yesod APP

mkYesod "APP" [parseRoutes|
    / TestR GET
|]

getTestR :: Handler RepJson
getTestR = jsonToRepJson $ object ["test".= ("test"::Text)]
main::IO()
main = warpDebug 3001 APP

this is what I get when I use runhaskell

api.hs:18:12:
    Couldn't match expected type `RepJson' with actual type `Value'
    Expected type: Handler RepJson
      Actual type: HandlerT APP IO Value
    In the expression:
      jsonToRepJson $ object ["test" .= ("test" :: Text)]
    In an equation for `getTestR':
        getTestR = jsonToRepJson $ object ["test" .= ("test" :: Text)]
like image 701
miah_ Avatar asked Mar 24 '23 17:03

miah_


1 Answers

You must convert your value toJSON.

Eg.:

jsonToRepJson $ object [("result", toJSON resultValue)]

:)

You can read about that change in Yesod 1.2

like image 145
josejuan Avatar answered Apr 05 '23 21:04

josejuan