Haskell:从Data.Binary.Get捕获异常

时间:2011-03-27 17:28:50

标签: exception haskell

我有以下代码:

import Data.Binary.Get
import qualified Data.ByteString.Lazy as L
import qualified Control.Exception as E

main = do
    let dat = L.pack [1,2,3,4]
    E.catch (E.evaluate $ runGet getWord32be dat) (\_ -> return 0) (return 1)
    putStrLn "Done"

我收到以下错误:

Couldn't match expected type `m1 t -> m a'
       against inferred type `IO GHC.Word.Word32'
In a stmt of a 'do' expression:
    E.catch
      (E.evaluate $ runGet getWord32be dat) (\ _ -> return 0) (return 1)

但我无法弄清楚错配是什么。有人可以开导吗?

1 个答案:

答案 0 :(得分:1)

Catch只需要两个参数。你给它三个。