使用Error类型类

Sib*_*ibi 2 error-handling haskell typeclass

Error类型类的用途是什么:

class Error a where
    noMsg :: a
    strMsg :: String -> a
Run Code Online (Sandbox Code Playgroud)

还有另一个类型命名MonadError,它在monadic计算中是有意义的.但是在哪里Error使用?我没见过的使用noMsgstrMsg尚未在任何地方.

Dan*_*ner 5

由于历史原因,Monad m类型类包括fail :: String -> m a.为了Either e实现这样的方法,我们必须有办法把a String变成a e; 该Error类型类的发明通过允许这样strMsg.添加noMsg是额外的便利.