Hi Patrick, On 2 August 2011 13:57, Patrick Browne <[email protected]> wrote: > What is the difference between using a class context and deriving in > data type declaration?
A class context simply says something about the types involved in the construction. In your example, > data Eq a => Set1 a = NilSet1 | ConsSet1 a (Set1 a) the type `a` must have an instance of `Eq`. This does not imply that `Set1` itself has an instance of `Eq`. On the other hand, the `deriving` keyword tells the compiler that you'd like it to try and derive a default instance for a class. In your example, this results in an instance of `Eq Set2`. Hopefully that should explain why you had: > (NilSet1) == (NilSet1) -- no instance, error > (NilSet2) == (NilSet2) -- True All the best, Nick _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
