Changes between Version 76 and Version 77 of Commentary/Compiler/GenericDeriving


Ignore:
Timestamp:
Aug 2, 2016 10:46:35 PM (3 years ago)
Author:
RyanGlScott
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/GenericDeriving

    v76 v77  
    553553
    554554We could even let users specify which of the two types of deriving they want:
    555 {{{
    556 newtype MyInt = MyInt Int deriving (newtype GBinary, default GShow)
    557 }}}
    558 Here, we re-use the keywords `newtype` and `default` to specify that the `GBinary` instance should be created using GND (so that we do not have the unnecessary extra tag in the binary encoding), but `GShow` should use the "generic" instance (so that we still print "MyInt").
    559 
    560 Of course, then we'd need to:
    561 1. Agree on the syntax;
    562 2. Decide what to do when users ask for e.g. `... deriving (newtype Typeable)`.
     555
     556{{{#!hs
     557newtype MyInt = MyInt Int
     558  deriving newtype  GBinary
     559  deriving anyclass GShow
     560}}}
     561
     562Here, we use the keywords `newtype` and `anyclass` to specify that the `GBinary` instance should be created using GND (so that we do not have the unnecessary extra tag in the binary encoding), but `GShow` should use the "generic" instance (so that we still print `"MyInt"`). See the [wiki:Commentary/Compiler/DerivingStrategies deriving strategies page] for information.
    563563
    564564