Automatically deriving Generic for every algebraic data type

Oleg Grenrus oleg.grenrus at iki.fi
Thu Feb 4 13:17:34 UTC 2016


Hi,

sometimes I want to use Generic derivation, but don’t want expose the Generic
instance outside the module.  The reason, is that for some types I want to
export only smart constructors / modifier lenses; yet the structure is probably
simple enough to benefit from `Generic`.

If it will be possible to restrict export of the Generic instance, then I don’t
see problem of auto-deriving it for everything possible though.

- Oleg

> On 04 Feb 2016, at 14:28, Wolfgang Jeltsch <g9ks157k at acme.softbase.org> wrote:
> 
> 
> Am Donnerstag, den 04.02.2016, 14:19 +0200 schrieb Wolfgang Jeltsch:
>> 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.
> 
> I want to add that this would probably allow us to implement all the
> other deriving mechanisms (for standard classes, for Functor, etc.)
> entirely in libraries, using generic programming, without forcing users
> to change their code by adding deriving of Generic. Maybe a future
> standard Haskell would not even have deriving rules hardwired into the
> language anymore (which always felt somehow wrong to me). Wouldn’t this
> be great? ;-)
> 
> All the best,
> Wolfgang
> 
> 
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org <mailto:ghc-devs at haskell.org>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs <http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20160204/3a200a80/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20160204/3a200a80/attachment-0001.sig>


More information about the ghc-devs mailing list