add GHC.HetMet.{hetmet_kappa,hetmet_kappa_app}
[ghc-base.git] / Unsafe / Coerce.hs
1 {-# LANGUAGE CPP, NoImplicitPrelude, MagicHash #-}
2
3 -----------------------------------------------------------------------------
4 -- |
5 -- Module      :  Unsafe.Coerce
6 -- Copyright   :  Malcolm Wallace 2006
7 -- License     :  BSD-style (see the LICENSE file in the distribution)
8 --
9 -- Maintainer  :  libraries@haskell.org
10 -- Stability   :  experimental
11 -- Portability :  portable
12 --
13 -- The highly unsafe primitive 'unsafeCoerce' converts a value from any
14 -- type to any other type.  Needless to say, if you use this function,
15 -- it is your responsibility to ensure that the old and new types have
16 -- identical internal representations, in order to prevent runtime corruption.
17 --
18 -- The types for which 'unsafeCoerce' is representation-safe may differ
19 -- from compiler to compiler (and version to version).
20 --
21 --   * Documentation for correct usage in GHC will be found under
22 --     'unsafeCoerce#' in GHC.Base (around which 'unsafeCoerce' is just a
23 --     trivial wrapper).
24 --
25 --   * In nhc98, the only representation-safe coercions are between Enum
26 --     types with the same range (e.g. Int, Int32, Char, Word32),
27 --     or between a newtype and the type that it wraps.
28
29 module Unsafe.Coerce (unsafeCoerce) where
30
31 #if defined(__GLASGOW_HASKELL__)
32 import GHC.Prim (unsafeCoerce#)
33 unsafeCoerce :: a -> b
34 unsafeCoerce = unsafeCoerce#
35 #endif
36
37 #if defined(__NHC__)
38 import NonStdUnsafeCoerce (unsafeCoerce)
39 #endif
40
41 #if defined(__HUGS__)
42 import Hugs.IOExts (unsafeCoerce)
43 #endif