newtype coercion wrapping status
mail at joachim-breitner.de
Fri Sep 6 20:05:23 CEST 2013
Am Freitag, den 06.09.2013, 16:47 +0000 schrieb Simon Peyton-Jones:
> * 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:
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:
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 ()
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
Size: 198 bytes
Desc: This is a digitally signed message part
More information about the ghc-devs