سؤال

What is the use of Error typeclass:

class Error a where
    noMsg :: a
    strMsg :: String -> a

There is also another typeclass named MonadError which makes sense in monadic computation. But where is Error used ? I haven't seen the usage of noMsg and strMsg yet anywhere.

هل كانت مفيدة؟

المحلول

For historical reasons, the Monad m typeclass includes fail :: String -> m a. For Either e to implement such a method, we must have a way to turn a String into an e; the Error typeclass was invented to allow this via strMsg. The addition of noMsg is an additional convenience.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top