[Haskell-cafe] Why distinct tyvars in instance declarations?

Josh Hoyt joshhoyt at gmail.com
Sat Jun 25 15:22:50 EDT 2005


I'm a new Haskeller, and I'm running into a problem attempting to
declare certain types as instances. I was attempting something that's
effectively equivalent to:

> class Foo a
> instance Foo (Either b b)

but GHC complains:

>     Illegal instance declaration for `Foo (Either b b)'
>         (The instance type must be of form (T a b c)
>          where T is not a synonym, and a,b,c are distinct type variables)
>     In the instance declaration for `Foo (Either b b)'

and so I looked in the report
(http://www.haskell.org/onlinereport/decls.html#sect4.3.2) and found:

> The general form of the corresponding instance declaration is:
> instance cx' => C (T u1 ... uk) where { d }
> where k>=0. The type (T u1 ... uk) must take the form of a type constructor T applied to simple type variables u1, ... uk; furthermore, T must not be a type synonym, and *the ui must all be distinct*. (emphasis mine)

My question is, why this restriction that the types must be distinct?

In particular, I'd like to declare a very specific type (Either String
String) as an instance. What techniques can I use to accomplish this?

Josh Hoyt

More information about the Haskell-Cafe mailing list