Automatically deriving Generic for every algebraic data type

Roman Cheplyaka roma at ro-che.info
Thu Feb 4 14:21:18 UTC 2016


On 02/04/2016 02:19 PM, Wolfgang Jeltsch wrote:
> Hi,
> 
> if you do generic programming these days, you can use DeriveAnyClass to
> write code like the following (where Serializable is a class with a
> generic default implementation):
> 
>> data Tree a = Leaf | Branch (Tree a) a (Tree a)
>>               deriving (Generic, Serializable)
> 
> It would be great, if you could just write the following instead:
> 
>> data Tree a = Leaf | Branch (Tree a) a (Tree a) deriving Serializable
> 
> This would correspond exactly to what you do when using standard Haskell
> deriving. It could be made possible by letting the compiler instantiate
> the Generic class automatically every time an algebraic data type is
> declared. A potential downside of this would be that programmers would
> not be able to define non-standard instances of Generics, but I actually
> cannot see that this is very useful anyhow.
> 
> Any comments?

GHC.Generics already have an unfair advantage over the alternative (and
arguably, superior) libraries, such as generics-sop. I wouldn't want to
give it even more special treatment than it receives right now.

Roman

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20160204/1d6fe495/attachment.sig>


More information about the ghc-devs mailing list