Haskell 如何使用catchiorerror作为catch?

Haskell 如何使用catchiorerror作为catch?,haskell,exception,try-catch,Haskell,Exception,Try Catch,我在源代码中找到了这个定义 catchIOError :: IO a -> (IOError -> IO a) -> IO a catchIOError = catch 如果我想使用catch而不是catchIOError获得相同的结果,我该怎么办 catchIOError (readFile "test") (\_ -> return "") 然后像这样使用它: catch (readFile "test") (\_ -> return "") 它将抛出一个

我在源代码中找到了这个定义

catchIOError :: IO a -> (IOError -> IO a) -> IO a
catchIOError = catch
如果我想使用
catch
而不是
catchIOError
获得相同的结果,我该怎么办

catchIOError (readFile "test") (\_ -> return "")
然后像这样使用它:

catch (readFile "test") (\_ -> return "")
它将抛出一个关于变量类型的异常

Ambiguous type variable ‘e0’ arising from a use of ‘catch’
prevents the constraint ‘(Exception e0)’ from being solved.
Probable fix: use a type annotation to specify what ‘e0’ should be.
换句话说,有没有一种方法可以在不定义新函数的情况下限制类型。

使用类型注释:

(catch :: IO a -> (IOError -> IO a) -> IO a) (readFile "test") (\_ -> return "")
使用类型批注:

(catch :: IO a -> (IOError -> IO a) -> IO a) (readFile "test") (\_ -> return "")