[Haskell-beginners] Problems with typeclasses instances

Antoine Latter aslatter at gmail.com
Wed Jul 13 16:01:39 CEST 2011


On Wed, Jul 13, 2011 at 7:56 AM, ARJANEN Loïc Jean David
<arjanen.loic at gmail.com> wrote:

>
> If I compile without any option, I get as expected an error because of
> the type synonym instance. If I remove the instance for String, I also
> get as expected an error because Char is not an instance of Dummy. But
> if I add (as suggested in the first error message) the GHC's option
> -XTypeSynonymInstances, I get an error because of overlapping
> instances, even if Char is still not an instance of Dummy and I don't
> see how String could be eligible for the (Dummy t) => Dummy [t]
> instance...
>

This is one of the trickier bits about Haskell typeclasses. The instance:

> instance (Dummy t) => Dummy [t]

can be read in English as:

"The type [t] is an instance of Dummy. Also, using this instance is a
compilation failure if t is not an instance of Dummy."

More succinctly, the information to the left of the (=>) is not used
at all in instance resolution. It does, however, bring the constraint
into scope in the body of the instance declaration, so it isn't
useless.

Antoine

> Thanks in advance for your help,
> ARJANEN Loic.
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list