[Haskell-cafe] Problems instancing a class

Roberto Zunino roberto.zunino at sns.it
Fri Feb 17 13:44:04 EST 2006


Juan Carlos Arevalo Baeza wrote:

 > type Context = HT.HashTable String String
[snip]
 > Illegal instance declaration for `MyClass Context'
 >    (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 `MyClass Context'

"type" introduce a type synonym, and Haskell98 forbids these in 
instances, so GHC complains. GHC also lifts this restriction when 
invoked with -fglasgow-exts .

http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#type-synonyms

 >   If I use "data" instead of "type", it works:
 >
 > data Context = C (HT.HashTable String String)

This is fine: data (and newtype) declarations do not introduce type 
synonyms, but a genuine new type.

Regards,
Roberto Zunino.


More information about the Haskell-Cafe mailing list