Consider the following test function:
testError :: (Error e, MonadError e m) => Bool -> m ()
testError True = return ()
testError False = throwError $ strMsg "hello world"
At the GHCi prompt, I can do the following:
*Main> testError False :: Either String ()
Left "hello world"
*Main> testError True :: Either String ()
Right ()
Because I pointed out that as the type of the String _ expression, it uses the String MonadError implementation. I assumed that if I did not define the implementation of MonadError myself, or called this function from another function, allowing me to enter a type, I would get an error. Instead of this:
*Main> testError True
*Main> testError False
*** Exception: user error (hello world)
It seems that GHCi provides some "monastic" monad error. Can someone explain what is going on here?
source
share