What is the difference between using a class context and deriving in
data type declaration?
Are there certain situations in which one or the other is preferred?

data Eq a => Set1 a = NilSet1 | ConsSet1 a (Set1 a)
data         Set2 a = NilSet2 | ConsSet2 a (Set2 a) deriving Eq

(NilSet1) == (NilSet1) -- no instance, error
(NilSet2) == (NilSet2) -- True

-- seems OK
type Type1 = Set1 Integer
type Type2 = Set2 Integer

-- seems OK
data Data1 = Set1 | Set2

-- Seems to have same type
:t ConsSet2 1 NilSet2
ConsSet2 1 NilSet2 :: forall t. (Num t) => Set2 t
:t ConsSet1 1 NilSet1
ConsSet1 1 NilSet1 :: forall t. (Num t) => Set1 t




-- Pat


This message has been scanned for content and viruses by the DIT Information 
Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to