<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Should we test drive <a href="https://github.com/ghc-proposals/ghc-proposals" class="">https://github.com/ghc-proposals/ghc-proposals</a><div class="">on this proposal?</div><div class=""><br class=""></div><div class="">- Oleg</div><div class=""><br class=""></div><div class=""><div class=""><div><blockquote type="cite" class=""><div class="">On 17 Jul 2016, at 05:02, Ryan Scott <<a href="mailto:ryan.gl.scott@gmail.com" class="">ryan.gl.scott@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">I'm pursuing a fix to Trac #10598 [1], an issue in which GHC users do<br class="">not have fine-grained control over which strategy to use when deriving<br class="">an instance, especially when multiple extensions like<br class="">-XGeneralizedNewtypeDeriving and -XDeriveAnyClass are enabled<br class="">simultaneously. I have a working patch up at [2] which would fix the<br class="">issue, but there's still a lingering question of what the right syntax<br class="">is to use here. I want to make sure I get this right, so I'm<br class="">requesting input from the community.<br class=""><br class="">To condense the conversation in [1], there are three means by which<br class="">you can derive an instance in GHC today:<br class=""><br class="">1. -XGeneralizedNewtypeDeriving<br class="">2. -XDeriveAnyClass<br class="">3. GHC's builtin algorithms (which are used for deriving Eq, Show,<br class="">Functor, Generic, Data, etc.)<br class=""><br class="">The problem is that it's sometimes hard to know which of the three<br class="">will kick in when you say `deriving C`. To resolve this ambiguity, I<br class="">want to introduce the -XDerivingStrategies extension, where a user can<br class="">explicitly request which of the above ways to derive an instance.<br class=""><br class="">Here are some of the previously proposed syntaxes for this feature,<br class="">with their perceived pros and cons:<br class=""><br class="">----- Pragmas<br class="">  * Examples:<br class="">      - newtype T a = T a deriving ({-# BUILTIN #-} Eq, {-# GND #-}<br class="">Ord, {-# DAC #-} Read, Show)<br class="">      - deriving {-# BUILTIN #-} instance Functor T<br class="">  * Pros:<br class="">      - Backwards compatible<br class="">      - Requires no changes to Template Haskell<br class="">  * Cons:<br class="">      - Unlike other pragmas, these ones can affect the semantics of a program<br class="">----- Type synonyms<br class="">  * Examples:<br class="">      - newtype T a = T a deriving (Builtin Eq, GND Ord, DAC Read, Show)<br class="">      - deriving instance Builtin (Functor T)<br class="">  * Pros:<br class="">      - Requires no Template Haskell or parser changes, just some<br class="">magic in the typechecker<br class="">      - Backwards compatible (back to GHC 7.6)<br class="">  * Cons:<br class="">      - Some developers objected to the idea of imbuing type synonyms<br class="">with magical properties<br class="">----- Multiple deriving clauses, plus new keywords<br class="">  * Examples:<br class="">      - newtype T a = T a<br class="">          deriving Show<br class="">          deriving builtin instance (Eq, Foldable)<br class="">          deriving newtype instance Ord<br class="">          deriving anyclass instance Read<br class="">      - deriving builtin instance Functor T<br class="">  * Pros:<br class="">      - Doesn't suffer from the same semantic issues as the other suggestions<br class="">      - (Arguably) the most straightforward-looking syntax<br class="">  * Cons:<br class="">      - Requires breaking changes to Template Haskell<br class="">      - Changes the parser and syntax significantly<br class=""><br class="">Several GHC devs objected to the first two of the above suggestions in<br class="">[1], so I chose to implement the "Multiple deriving clauses, plus new<br class="">keywords" option in [2]. However, I'd appreciate further discussion on<br class="">the above options, which one you prefer, and if you have other<br class="">suggestions for syntax to use.<br class=""><br class="">Ryan S.<br class="">-----<br class="">[1] <a href="https://ghc.haskell.org/trac/ghc/ticket/10598" class="">https://ghc.haskell.org/trac/ghc/ticket/10598</a><br class="">[2] <a href="https://phabricator.haskell.org/D2280" class="">https://phabricator.haskell.org/D2280</a><br class="">_______________________________________________<br class="">ghc-devs mailing list<br class=""><a href="mailto:ghc-devs@haskell.org" class="">ghc-devs@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs<br class=""></div></blockquote></div><br class=""></div></div></body></html>