X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fprelude%2Fprimops.txt.pp;h=adb2e110ff8ced4fc4348f767daa93185a37c4bf;hb=a385f0af5ea320a18d580f6a36c59c55b3516efd;hp=61a696463edec2ab9efa2fd5c923e7b95af10dca;hpb=4f92da533cd1c7b5f41ef8794ee6a284f1680413;p=ghc-hetmet.git diff --git a/compiler/prelude/primops.txt.pp b/compiler/prelude/primops.txt.pp index 61a6964..adb2e11 100644 --- a/compiler/prelude/primops.txt.pp +++ b/compiler/prelude/primops.txt.pp @@ -1808,7 +1808,14 @@ pseudoop "unsafeCoerce#" known to be empty. Also, a {\tt newtype} of a type {\tt T} has the same representation at runtime as {\tt T}. - Other uses of {\tt unsafeCoerce\#} are undefined. + Other uses of {\tt unsafeCoerce\#} are undefined. In particular, you should not use + {\tt unsafeCoerce\#} to cast a T to an algebraic data type D, unless T is also + an algebraic data type. For example, do not cast {\tt Int->Int} to {\tt Bool}, even if + you later cast that {\tt Bool} back to {\tt Int->Int} before applying it. The reasons + have to do with GHC's internal representation details (for the congnoscenti, data values + can be entered but function closures cannot). If you want a safe type to cast things + to, use {\tt Any}, which is not an algebraic data type. + } -- NB. It is tempting to think that casting a value to a type that it doesn't have is safe