newtype coercion wrapping status
Joachim Breitner
mail at joachim-breitner.de
Fri Sep 6 20:05:23 CEST 2013
Hi,
Am Freitag, den 06.09.2013, 16:47 +0000 schrieb Simon Peyton-Jones:
> So
>
> * for newtypes
> newtype N a = MkN <rep-ty>
> the coercion is between (N a) and its representation type <rep_ty>.
> The coercion is allowed if the data constructor MkN is in scope
>
> * for data types (T a), the coercion is between (T a) and (T b),
> The coercion is allowed if the roles allow it.
>
> The two are handled quite differently.
>
> OK? This is far from obvious (since I was very confused about it), so worth writing up on the design page. As well as implementing.
Sounds reasonable. Implementation is simple, I just remove the check
that I had added:
https://github.com/nomeata/ghc/commit/46c6c7
https://github.com/nomeata/ghc-testsuite/commit/d5c13
One question which is left open, which I cannot answer: Are there
situations where the library author wants to prevent coercion, but needs
a non-Nominal role for some other reasons? But we’ll see.
> Roles are in HEAD so you can use them right now.
I know, my patch is against head and already makes use of roles:
TcCoercibleFail.hs:16:8:
No instance for (Coercible (Map Int ()) (Map Age ()))
because the first type argument of ‛Map’ has role Nominal,
but the arguments ‛Int’ and ‛Age’ differ
arising from a use of ‛coerce’
In the expression: coerce
In the expression: coerce $ Map one () :: Map Age ()
In an equation for ‛foo3’: foo3 = coerce $ Map one () :: Map Age ()
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/b533b142/attachment.pgp>
More information about the ghc-devs
mailing list