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

Michael Mossey mpm at alumni.caltech.edu
Sun Nov 1 11:32:34 EST 2009

Brent Yorgey wrote:
> The m -> e thing isn't a constraint that needs to be satisfied; it
> gives some extra information to help the compiler with inferring which
> instance to use.  In particular, "m -> e" says "the type chosen for m
> DETERMINES the type chosen for e"; put another way, "there cannot be
> two instances with the same type for m but different types for e".  So
> in this case you could not also make an instance
>   MonadError String (Either e).

Thanks, Brent.  Now what I'm a bit confused about:
if you wrote

instance (Error e) => MonadError e (Either e)

and no other instance with Either e, then the compiler would have only one 
choice. So why would it need the extra information in the functional 

On the other hand, if you added

instance (Error e) => MonadError String (Either e)

and didn't include the functional dependency, the compiler would still run 
into a problem with overlapping instances and have no way to decide, which 
I presume is still an error.

So it looks to me (no doubt because I don't understand correctly) that the 
functional dependency doesn't add any information or clarify any situation. 
Please explain!


More information about the Beginners mailing list