summaryrefslogtreecommitdiff
path: root/compiler/prelude/primops.txt.pp
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2008-04-21 15:21:30 +0000
committersimonpj@microsoft.com <unknown>2008-04-21 15:21:30 +0000
commitb6a155b281f223f328b617d3a7763688537b2ee3 (patch)
treec5bd4b8c1b0139048167bd05234593621f6a462d /compiler/prelude/primops.txt.pp
parent60714e2c04c5814faf560be5988ff4731ea70a65 (diff)
downloadhaskell-b6a155b281f223f328b617d3a7763688537b2ee3.tar.gz
Add clarifying comments about unsafeCoerce
Diffstat (limited to 'compiler/prelude/primops.txt.pp')
-rw-r--r--compiler/prelude/primops.txt.pp9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/prelude/primops.txt.pp b/compiler/prelude/primops.txt.pp
index 61a696463e..adb2e110ff 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