[Haskell-cafe] Type Class Query

Ketil Malde ketil+haskell at ii.uib.no
Tue Feb 3 09:11:10 EST 2004


Hal Daume III <hdaume at ISI.EDU> writes:

>> class Null a where
>>      nullify :: a -> a

Hmm...why not 

        class Null a where
                null :: a
(you are just throwing away the parameter anyway)?

>> I then tried the following:
>> 
>> instance Num a => Null a where
>>          nullify x = 0
>> 
>> but got the following error in Hugs
>> 
>> ERROR "C:\zero.hs":5 - Syntax error in instance head (constructor expected)

> This is because instance declarations like this are illegal.  Basically, 
> there has to be a constructor on the RHS of the =>.  

In this case, I'd expect a type (and not a class, like "Null a" is)

I'm a bit puzzled by the terminology: What does "constructor" mean in
this context?  Normally, I'd use (unqualified) "constructor" to mean
data constructor, as in Just, Nothing, Left, Right and so on.

(From the obvious Prelude stuff:
        data Maybe a = Just a | Nothing
        data Either a b = Left a | Right b
)

Unless I'm completely confused, perhaps Hugs should expect a "type
constructor" instead of just a "constructor" in its error message?  Or
perhaps it could simply say "type"?

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Haskell-Cafe mailing list