<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I agree with David that using explicit `coerce`s can be quite verbose and may need ScopedTypeVariables and InstanceSigs. But visible type application should always work, because class methods always have a fixed type argument order. Regardless, requiring users to do all this for GND on Monad would be frustrating.</div><div class=""><br class=""></div><div class="">Actually, I just had an insight about this: there is no reason to use one deriving strategy for all methods in an instance. I can think of 4 ways to fill in the implementation of a class method in an instance:</div><div class=""><br class=""></div><div class="">1. Explicit, hand-written implementation</div><div class="">2. Defaulting to the implementation written in the class (or `error "undefined method"` in the absence of a default. This is essentially the default default.)</div><div class="">3. Stock implementation provided by GHC</div><div class="">4. Coerce</div><div class=""><br class=""></div><div class="">Ways 2, 3, and 4 all have extra restrictions: Way 2 might have extra type constraints due to a `default` signature. Way 3 restricts the choice of class and type. Way 4 works only on newtypes and then imposes role restrictions on the method's type.</div><div class=""><br class=""></div><div class="">GHC provides a `deriving` mechanism so that you can request Way 2 (`default`), 3 (`stock`), or 4 (`newtype`) to fill in every method in a class. But there's no need to provide this feature at such a course granularity. What about:</div><div class=""><br class=""></div><div class=""></div><blockquote type="cite" class=""><div class="">newtype N a = MkN (Foo a)</div><div class="">instance Blah a => C (N a) where</div><div class="">  meth1 = ...</div><div class="">  deriving default meth2   -- a bit silly really, as you can just leave meth2 out</div><div class="">  deriving stock meth3     -- also silly, as C isn't a stock class, but you get the idea</div><div class="">  deriving newtype meth4</div></blockquote><div class=""><br class=""></div><div class="">We could also imagine</div><div class=""><br class=""></div><div class=""></div><blockquote type="cite" class=""><div class="">deriving newtype instance Blah a => Monad (N a) where</div><div class="">  deriving default join   -- not so silly anymore!</div></blockquote><div class=""><br class=""></div><div class="">This syntax allows a `where` clause on standalone deriving allowing you to override the overall `deriving` behavior on a per-method basis.</div><div class=""><br class=""></div><div class="">I actually quite like this extension...</div><div class=""><br class=""></div><div class="">Richard</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 8, 2017, at 11:54 PM, David Feuer <<a href="mailto:david.feuer@gmail.com" class="">david.feuer@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class="">You *can* do this, but it's often not so concise. When the type constructor has parameters, you need to pin them down using ScopedTypeVariables. So you end up needing to give a signature for the method type in order to bring into scope variables you then use in the argument to coerce. If you have<div dir="auto" class=""><br class=""></div><div dir="auto" class="">newtype Foo f a = Foo (Foo f a)</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">then you may need</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">instance Bar f => Bar (Foo f) where</div><div dir="auto" class="">  bah = coerce (bah @ f @ a)</div><div dir="auto" class="">    :: forall a . C a => ...</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">to pin down the C instance.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">If you don't want to use explicit type application (e.g., you're using a library that does not claim to have stable type argument order), things get even more verbose.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Jan 8, 2017 11:32 PM, "Joachim Breitner" <<a href="mailto:mail@joachim-breitner.de" class="">mail@joachim-breitner.de</a>> wrote:<br type="attribution" class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br class="">
<br class="">
just responding to this one aspect:<br class="">
<br class="">
Am Sonntag, den 08.01.2017, 21:16 -0500 schrieb David Feuer:<br class="">
> but using defaults for<br class="">
> the others would give poor implementations. To cover this case, I<br class="">
> think it would be nice to add per-method GND-deriving syntax. This<br class="">
> could look something like<br class="">
><br class="">
> instance C T where<br class="">
>   deriving f<br class="">
>   g = ....<br class="">
<br class="">
Assuming<br class="">
  newtype T = MkT S<br class="">
<br class="">
You can achieve this using<br class="">
<br class="">
  instance C T where<br class="">
     f = coerce (f @F)<br class="">
     g = ....<br class="">
<br class="">
(which is precisely what GND does), so I don’t think any new syntax is<br class="">
needed here.<br class="">
<br class="">
Greetings,<br class="">
Joachim<br class="">
<br class="">
--<br class="">
Joachim “nomeata” Breitner<br class="">
  <a href="mailto:mail@joachim-breitner.de" class="">mail@joachim-breitner.de</a> • <a href="https://www.joachim-breitner.de/" rel="noreferrer" target="_blank" class="">https://www.joachim-breitner.<wbr class="">de/</a><br class="">
  XMPP: <a href="mailto:nomeata@joachim-breitner.de" class="">nomeata@joachim-breitner.de</a> • OpenPGP-Key: 0xF0FBF51F<br class="">
  Debian Developer: <a href="mailto:nomeata@debian.org" class="">nomeata@debian.org</a><br class="">______________________________<wbr class="">_________________<br class="">
Glasgow-haskell-users mailing list<br class="">
<a href="mailto:Glasgow-haskell-users@haskell.org" class="">Glasgow-haskell-users@haskell.<wbr class="">org</a><br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/glasgow-<wbr class="">haskell-users</a><br class="">
<br class=""></blockquote></div></div>
_______________________________________________<br class="">Glasgow-haskell-users mailing list<br class=""><a href="mailto:Glasgow-haskell-users@haskell.org" class="">Glasgow-haskell-users@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users<br class=""></div></blockquote></div><br class=""></body></html>