proposal: add 'unsafeCoerce'

Donald Bruce Stewart dons at cse.unsw.edu.au
Mon Nov 20 08:48:59 EST 2006


simonmarhaskell:
> Casting boxed types to unboxed types or vice versa is pretty much 
> guaranteed to end in tears.

Ah, you forget the 2004 IOHCC ;)

    module Main where{import GHC.Base;(&)=unsafeCoerce#;main=print(tail
    ((\(!)->map(\(?)->C#((&)(indexWordArray#((&)(?))4#)))(!))([106,117,
    115,116,32,97,32,115,105,109,112,108,101,32,102,117,110,99,116,105,
    111,110,97,108,32,108,97,110,103,117,97,103,101,(0x11)]::[Int])));}

    $ ./a.out
    "just a simple functional language"

Admittedly, I took about 3 days to find an example that didn't end in
segf^h^h^h^htears.. :)

-- Don

P.S. And it seems this only ever compiled with a snapshot of ghc 6.3.


More information about the Libraries mailing list