[Haskell-beginners] several questions: multi-param typeclasses, etc.

Michael Mossey mpm at alumni.caltech.edu
Sun Nov 1 10:15:17 EST 2009


I'm trying to understand multi-param typeclasses; a particular one
(MonadError); and functional dependencies.

For example, throwError in in the MonadError class definition:

class Monad m => MonadError e m | m -> e where
    throwError :: e -> m a


The concept of a multi-parameter class is a litte tricky. It's no
longer so simple to say that "ONE type is AN instance of ONE class."
Instead, it seems more appropriate to say that "in a context where e
and m fulfill the criteria for class MonadError, the function
throwError is available."

In a sense, there is no single type that is an instance of MonadError.

Is this the right way to put it?

So I went looking for an instance of MonadError, in particular with
use with Either.

I couldn't find actual source code with an instance, but the Haddock
documentation lists this:

Instances:

   Error e => MonadError e (Either e)

The code doesn't give the definition, but I suppose it would be:

             throwError e = Left e ???

Now I'm interested in understanding this functional dependency between
m and e. For the compiler to decide that a particular instance's
definition of throwError is available, it  must decide that

   e is of class Error (it is given by class constraint)
   m is a Monad (Either e is such)
   and then this m -> e thing: I don't know how to put this into words

Any explanation/clarification/correction appreciated.

Thanks,
Mike



More information about the Beginners mailing list