我遇到的问题是readFile
返回一个IO String
但 parse 需要一个正则String
(或在下面的示例中 a 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 }