proposal: add 'unsafeCoerce'
simonmarhaskell at gmail.com
Wed Nov 22 05:38:53 EST 2006
Iavor Diatchki wrote:
> I just wanted to point out that even the 'reasonable' uses of
> 'unsafeCoerce' (i.e., where a type does not appear directly in a
> value) may not be compatible between different implementations.
> Consider, for example, an implementation which turns a polymorphic
> program into a monomorphic one by generating different versions of
> functions for each of its instantiations (this is not a new idea). In
> particular, one also has to specialize constructor functions, which
> amounts to specializing datatypes. For example, 'Either at Int@Char'
> and 'Either at Int@Bool' become completely separate types. In addition,
> we may choose to add only those constructors of a specialized type
> that actually appear in the program. For example, 'Either at Int@Char'
> may have both constructors 'Left at Int@Char' and 'Righ at Int@Char', while
> 'Either at Int@Bool' may only have a single constructor 'Right at Int@Bool'.
> Now, if we use an integer tag to distinguish constructors, then by
> using 'unsafeCoerce' we may end up casting 'Left at Int@Char' into
> 'Right at Int@Bool'.
Quite right. I didn't mean to suggest that this property of unsafeCoerce should
be a defined part of its behaviour across implementations, just that it
currently works in GHC.
More information about the Libraries