Narrower (per-method) GND
David Feuer
david.feuer at gmail.com
Mon Jan 9 04:54:35 UTC 2017
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
newtype Foo f a = Foo (Foo f a)
then you may need
instance Bar f => Bar (Foo f) where
bah = coerce (bah @ f @ a)
:: forall a . C a => ...
to pin down the C instance.
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.
On Jan 8, 2017 11:32 PM, "Joachim Breitner" <mail at joachim-breitner.de>
wrote:
> Hi,
>
> just responding to this one aspect:
>
> Am Sonntag, den 08.01.2017, 21:16 -0500 schrieb David Feuer:
> > but using defaults for
> > the others would give poor implementations. To cover this case, I
> > think it would be nice to add per-method GND-deriving syntax. This
> > could look something like
> >
> > instance C T where
> > deriving f
> > g = ....
>
> Assuming
> newtype T = MkT S
>
> You can achieve this using
>
> instance C T where
> f = coerce (f @F)
> g = ....
>
> (which is precisely what GND does), so I don’t think any new syntax is
> needed here.
>
> Greetings,
> Joachim
>
> --
> Joachim “nomeata” Breitner
> mail at joachim-breitner.de • https://www.joachim-breitner.de/
> XMPP: nomeata at joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F
> Debian Developer: nomeata at debian.org
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/glasgow-haskell-users/attachments/20170108/90334c88/attachment.html>
More information about the Glasgow-haskell-users
mailing list