[Haskell-cafe] Deriving instances with GADTs
tim at timcowlishaw.co.uk
Thu Aug 4 09:16:51 CEST 2011
2011/8/4 José Pedro Magalhães <jpm at cs.uu.nl>:
> Here you seem to be using newtype deriving in particular, which behaves
> differently from standard deriving. Compiling with -ddump-deriv will show
> you the instances GHC is generating, which can help in debugging.
Aah - this is very useful, thanks!
> Note however that deriving instances for GADTs is not trivial, in general.
> In particular, you should not assume that GHC knows that `s` can only be
> instantiated with `Buy` and `Sell` since (because we lack a proper kind
> system) nothing prevents you from later using, say, `Order Int Limit`
Aah - this is something like what I suspected (The type signature for
OrderListLevel doesn't preclude eg OrderListLevel Int which would need
an instance of (Eq|Show) for Order Int Limit, which does not exist.
> I describe the issue in more detail in the paper:
>> José Pedro Magalhães and Johan Jeuring. Generic Programming for Indexed
>> Color pdf: http://dreixel.net/research/pdf/gpid.pdf
>> Greyscale pdf: http://dreixel.net/research/pdf/gpid_nocolor.pdf
Oh, brilliant, thank you! I'll take a look now.
More information about the Haskell-Cafe