proposal: add 'unsafeCoerce'

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Mon Nov 20 16:19:15 EST 2006


Taral <taralx at gmail.com> writes:

> >     * casting from a newtype to the contained value (or vice versa).
> 
> Why do you need to cast for this? You have "casting" operators in the
> form of the constructor and (synthesized) destructor.

OK, to be more explicit,

    newtype Wrapper a = Wrap a
    convert :: [a] -> [Wrapper a]
    convert xs = map Wrap xs

Here, the convert function actually traverses the list at runtime.

    convert' xs = unsafeCoerce xs

But this version does not - it is a type-avoiding identity.

Regards,
    Malcolm


More information about the Libraries mailing list