newtype coercion wrapping status

Simon Peyton-Jones simonpj at
Sat Sep 7 19:16:35 CEST 2013

| In the current code, the
|         instance Coercible a b => Coercible (T a) (T b)
| is available for both data and newtypes, if T’s type argument has
| Representational role, but independent of any constructor presence. See
| the note at
| for a concise and complete list of the conditions for a Coercible
| instance.

Right! I explained that badly the first time; thanks for clarifying Joachim.

So newtype and data behave alike, except that newtype has the *additional* property that if its constructor is available you can coerce to the representation type.  

| If I understood Simon’s last suggestion correctly than exporting a type
| constructor with a non-Nominal role means “I am fine if you cast this
| argument”. If this is not desired (e.g. maybe Ptr a is an example here),
| then the library author has to annotate the type argument as Nominal.

Yes, that's right.  In theory someone could want the coercible instance *plus* the nominal role, or vice versa, but I think we can jump that bridge if we come to it.


More information about the ghc-devs mailing list