[Haskell-beginners] Handling a MonadError

Stephen Tetley stephen.tetley at gmail.com
Mon May 30 23:23:11 CEST 2011


On 30 May 2011 22:17, Stephen Tetley <stephen.tetley at gmail.com> wrote:
> On 30 May 2011 20:35, Christopher Howard
>> More specifically: Why is there a pipe symbol followed by what looks
>> like a function definition in the "class" line?
>
> It is a functional dependency.
>
> Generally you can read it as "m uniquely determines e".
>

The simplest instance seems to be this one:

instance (Error e) => MonadError e (Either e) where
    throwError             = Left
    Left  l `catchError` h = h l
    Right r `catchError` _ = Right r

The functional dependency tells GHC that the error parameter 'e' is
the same type variable 'e' that is in monad parameter '(Either e)'



More information about the Beginners mailing list