[Haskell-cafe] Re: deriving

Hans Aberg haberg at math.su.se
Tue Apr 8 11:54:16 EDT 2008


On 8 Apr 2008, at 17:03, Christian Maeder wrote:
> "deriving Eq" i.e. following "data List a = List a" creates an  
> instance
> like:
>
>  instance Eq a => Eq (List a) where <compiler implementation>
>
> The problem was discussed for Stand-alone deriving declarations:
>
> http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html

There is a difference between
   data Foo a = Bar a | Baz String
   deriving instance Eq a => Eq (Foo a)
and
   data Eq a => Foo a = Bar a | Baz String deriving (Eq)

The second is more restrictive, as it requires Eq for the  
construction of Foo a, whereas the first could be construed to mean  
that Eq a is only required for the construction of Eq(Foo a). So the  
first could be used without Eq a if Eq(Foo a) is not needed. This is  
good when constructing libraries for general types.

   Hans





More information about the Haskell-Cafe mailing list