1

readFile返しますIO Stringが、解析は通常のString(または以下の例ではByteString) を期待するという問題があります。私は単に使用していますliftMが、以下の例はまだ失敗しています。何が問題ですか?

import Data.Aeson
import Data.Attoparsec
import Data.ByteString (ByteString, pack)
import Data.Maybe
import Network.HTTP
import Network.URI
import qualified Data.ByteString.Char8 as C
import Control.Monad

main = do
    myres  <-  liftM parse json (C.readFile "dummy.json")
    print myres

エラー:

Couldn't match expected type `t0 -> Parser a0'
            with actual type `Parser Value'
In the second argument of `liftM', namely `json'
In a stmt of a 'do' block:
  myres <- liftM parse json (C.readFile "dummy.json")
In the expression:
  do { myres <- liftM parse json (C.readFile "dummy.json");
       print myres }
4

1 に答える 1

5

の周り(parse json)の括弧が抜けているので、liftMに適用されますparse

于 2012-10-04T21:58:26.170 に答える