[Haskell-cafe] Error Monad and strings

Dietrich Epp depp at zdome.net
Tue Jul 27 18:57:46 EDT 2010


The "strMsg" method is used to implement the "fail" method in the  
resulting method, and calls to "fail" might be inserted into your code  
even if you don't explicitly call it.  An example in GHCi:

Prelude> :m + Control.Monad.Error
Prelude Control.Monad.Error> do { Just x <- return Nothing ; return  
x } :: Either String Int
Left "Pattern match failure in do expression at <interactive>:1:5-8"

Note that in the "Either String" monad, "failStr" is equal to "Left".

On 2010 July 27, at 15:32, Gerald Gutierrez wrote:

>
> Reading the Control.Monad.Error documentation, I see that the Error  
> class has noMsg and strMsg as its only two functions.
>
> Now, I understand that you can define your own Error instances such  
> as in example 1 of the documentation, so why the need to always  
> support strings via noMsg/strMsg ? What uses these? And if in my  
> code, I will never throw an error with a string, am I supposed to  
> implement these functions and then ignore them?



More information about the Haskell-Cafe mailing list