当我尝试时:
foos <- (return $ map (encode .> cs .> jsonToFoo body) `catch` r400
我收到以下类型错误:
/path/to/File.hs:47:78: error:
• Couldn't match type ‘(->) e0’ with ‘IO’
arising from a functional dependency between:
constraint ‘MonadBase IO ((->) e0)’ arising from a use of ‘r400’
instance ‘MonadBase ((->) r) ((->) r)’ at <no location info>
• In the second argument of ‘catch’, namely ‘r400’
In a stmt of a 'do' block:
foos <- (return $ map (encode .> cs .> jsonToFoo) body)
`catch` r400
In the expression:
do { (body :: [Value]) <- requireJsonBody;
foos <- (return $ map (encode .> cs .> jsonToFoo) body)
`catch` r400;
.... }
如果有办法,它涉及liftIO
,不是吗?
答案 0 :(得分:2)
我只是错过了catch
:
foos <- (return $ map (encode .> cs .> jsonToFoo body)
`catch` (\(e :: SomeException) -> r400)
太糟糕了,从类型错误来看,这对我来说并不是很明显。