[Haskell-cafe] Type Class Query
Tim Stitt
timothy.stitt at uwimona.edu.jm
Mon Feb 2 12:32:25 EST 2004
I'm experimenting with type classes in Haskell and tried to implement a
new class based on nullifying values of various types e.g.
nullify 6 = 0
nullify 7.6 = 0
nullify [1,2,3] = []
nullify Tree = Empty etc.
I set up my class as follows:
class Null a where
nullify :: a -> a
instance Null Int where
nullify x = 0
but get the following error when I invoke
nullify 6 on the Hugs command line:
ERROR - Unresolved overloading
*** Type : (Num a, Null a) => a
*** Expression : nullify 6
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)
Can anybody explain what I'm doing wrong ?
Thanks in advance,
Tim.
More information about the Haskell-Cafe
mailing list