[Haskell-cafe] Why do I have to specify (Monad m) here again?

David Tolpin david.tolpin at gmail.com
Sun Feb 18 13:24:39 EST 2007

> I think you, and probably Marc Weber as well, are confusing what a
> constraint on a class head means. Suppose you have:
> class Monad m => Foo m
> That constraint means that every instance of class Foo must also be an
> instance of class Monad. So, as I explained in my email to Marc, we
> must use:
> instance Monad m => Foo m
> And not:
> instance Foo m
> Because, in general, m isn't an instance of Monad.

Hi David,

Why the compiler cannot infer  class constraint on m from class definition in instance definition while it can in function type definition? If every instance of class Foo must be an insance of class Monad, then an instance of class Foo that is not an instance of class Monad cannot be declared could it?

Why the compiler cannot infer this constraint in instance declarations while it can in other contexts? How does the limitation follow from the type system? What is missing in the type system reasoning that prevents the Haskell compiler from using the proof?

There is no other choice for the time system than to allow only such instances of class Foo which are also instances of class Monad. Why then I have to say it explicitly again in case of instances, while other parts of the language allow inference?


More information about the Haskell-Cafe mailing list