[Haskell-cafe] Type Class Query

Hal Daume III hdaume at ISI.EDU
Mon Feb 2 14:08:34 EST 2004


> nullify 6 on the Hugs command line:
> 
> ERROR - Unresolved overloading
> *** Type       : (Num a, Null a) => a
> *** Expression : nullify 6 

Try 'nullify (6::Int)'.  Hugs (not due to any fault of its own) doesn't 
know that 6 is supposed to be of type Int, so if you also had an instance 
'Null Double', what should it do?

> 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 =>.  You can't just have a 
type variable.  -98 on hugs and -fglasgow-exts on ghc should lift this 
restrictuion, though I think you need -fallow-undecidable-instances in 
ghc and something else in Hugs...

 - Hal

-- 
 Hal Daume III                                   | hdaume at isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume



More information about the Haskell-Cafe mailing list