[Haskell-cafe] Problems instancing a class

Juan Carlos Arevalo Baeza jcab.lists at JCABs-Rumblings.com
Fri Feb 17 15:03:04 EST 2006


Gerrit van den Geest wrote:
> Mark
> Mark Jones has (some time ago) also written a very detailed e-mail 
> about this topic:
>
> http://www.haskell.org/pipermail/haskell/2000-October/006128.html

   I really don't understand anything spoken about in this message. I 
guess I need it translated into plain English :)

   I'd contend that, if Haskell is so good (and I believe it is), it 
should be more accessible to your average Joe, even if some might disagree.

> Grt
>
>> "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 
>>

   Thanx all for the replies. And here I thought I was compiling with 
extensions enabled. Blame it on using a compile script. Not that I had 
made the connection with this error...

   What really got me is that if I don't use a type synonym:

instance MyClass (HT.HashTable String String) where
    htLookup h var =
        do  result <- HT.lookup h var
            case result of
                Nothing -> return ""
                Just s -> return s

   it still complains:

Illegal instance declaration for `MyClass (HashTable String String)'
    (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 (HashTable String String)'

   even though the documentation in GHC states that HashTable is 
declared as "data".

   I haven't had time to read all the documentation you guys have 
forwarded to me, but still, I have one question. I was reading here:

http://hackage.haskell.org/trac/haskell-prime/wiki/TypeSynonymInstances

   and it says "The proposal is to allow type synonyms (fully applied, 
as ever) in instance heads. These would be fully expanded before any 
other restrictions on instance heads were checked", which is what sounds 
logical to me. And then it says "Not very useful without either 
FlexibleInstances </trac/haskell-prime/wiki/FlexibleInstances> or 
UndecidableInstances </trac/haskell-prime/wiki/UndecidableInstances>". I 
don't understand why. This extension would not depend on those other 
more involved extensions. Later down it says "Cons - Since constraints 
on the instance head refer to the expanded type, errors can be more 
obscure". Is that the reason? Because the other extensions would make 
errors clearer?

   I'd like to ask someone in the know to provide a good example that 
shows the reasons behind those statements are there. Preferably added to 
the Wiki :)

   How exactly is type undecidable if this is allowed? I found here:

http://hackage.haskell.org/trac/haskell-prime/wiki/FlexibleInstances

   an example of a non-terminating instance:

instance C b b => C (Maybe a) b

   I don't see how/where/when this would be non-terminating. I mean... 
if you now define an instance "C Int Int", then you actually also have 
"C (Maybe Int) Int", C (Maybe (Maybe Int)) Int" and so on, I can see 
that. But how exactly is that a problem? Can you show me a use of C that 
cannot work with that instance?

   Thanx!

JCAB



More information about the Haskell-Cafe mailing list