newtype coercion wrapping status
Joachim Breitner
mail at joachim-breitner.de
Fri Sep 6 17:11:20 CEST 2013
Hi,
Am Freitag, den 06.09.2013, 15:03 +0000 schrieb Simon Peyton-Jones:
> Sounds amazing Joachim -- great work.
Thanks!
> | Consider
> | data Foo a = MkFoo (a,a).
> | The (virtual) instance
> | instance Coercible a b => Coercible (Foo a) (Foo b)
> | can only be used when MkFoo is in scope, as otherwise the user could
> | break abstraction barriers. This is enforced.
>
> Whoa! Where did this instance come from? I thought that we generated precisely two (virtual) instances for Foo:
>
> instance Coercible a (b,b) => Coercible a (Foo b)
> instance Coercible (a,b) b => Coercible (Foo a) b
>
> and no others. That it. Done. That was precisely the payload of my message of 2 August, attached.
Well, that is the case when we want to unwrap a newtype. But this is not
the case here: We have a data type and we want to cast one of its type
arguments. Clearly, we want to have
instance Coercible a b => Coercible [a] [b]
right? The instance above is just an other instance (heh) of that form.
The two virtual instances that you mention only make sense for newtype,
_in addition_ to the usual “cast something inside this type”.
> [..]
>
> In short, I think that if you use the approach I outlined, all these problems go away. Am I wrong?
I believe so; I hope I just clarified it.
Greetings,
Joachim
--
Joachim “nomeata” Breitner
mail at joachim-breitner.de • http://www.joachim-breitner.de/
Jabber: nomeata at joachim-breitner.de • GPG-Key: 0x4743206C
Debian Developer: nomeata at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130906/3ffbbcb9/attachment.pgp>
More information about the ghc-devs
mailing list