我遇到的问题是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
ERROR:
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 }
答案 0 :(得分:5)
您错过(parse json)
周围的括号,因此liftM
已应用于parse