proposal: add 'unsafeCoerce'

John Meacham john at repetae.net
Mon Nov 27 23:12:35 EST 2006


On Tue, Nov 21, 2006 at 01:01:46PM +0000, Simon Marlow wrote:
> The language doesn't say anything about the runtime representation of 
> newtype. It so happens that the semantics lead to the obvious 
> implementation of a newtype as a type cast (that was the reason for 
>   introducing newtype, after all), but there's nothing to say you have to 
> implement it this way.  It would be wrong to require that unsafeCoerce let 
> you convert between a newtype and its underlying type across 
> implementations.

indeed, in fact, even though jhc uses the same representation for
newtypes as their value inside, unsafeCoerce here is still not valid.

The reason being that various core-transformations inside the compiler
are type directed, and the explicit knowledge that we are flipping
something to its newtype or back is very important to guarenteed the
safety of these optimizations.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈


More information about the Libraries mailing list