proposal: add 'unsafeCoerce'

Iavor Diatchki iavor.diatchki at gmail.com
Mon Nov 20 00:38:30 EST 2006


Hello,
I think that it is a really bad idea to make 'unsafeCoerce' a part of
the standard libraries.  As far as I understand, 'unsafeCoerce' is
only "safe" if the programmer assumes something about the
representations of values (in particular, that values of different
types have the same representations).  Haskell makes no such
guarantees so, by definition, any program that uses 'unsafeCoerce' is
using an implementation specific extension.  I was trying ot think of
cases where 'unsafeCoerce' might be somewhat safe, and the main
example I came up with is when the coersion happens on a phantom type.
 Are there other reasonably portable examples?
-Iavor



On 11/19/06, John Meacham <john at repetae.net> wrote:
> On Sun, Nov 19, 2006 at 01:30:16PM +0000, Neil Mitchell wrote:
> > Yhc translates Haskell to a well-typed (using rank-2 types, but not
> > explicitly typed) language. To translate this language back to Haskell
> > requires type annotations (which were lost ages ago), or lots of
> > unsafeCoerce, which is the significantly easier method. In practice
> > the unsafeCoerce's have never gone wrong on any compiler.
>
> This is what jhc does when compiling via ghc as well.
>
>         John
>
> --
> John Meacham - ⑆repetae.net⑆john⑈
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>


More information about the Libraries mailing list