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