1 {-# LANGUAGE CPP, NoImplicitPrelude, MagicHash #-}
3 -----------------------------------------------------------------------------
5 -- Module : Unsafe.Coerce
6 -- Copyright : Malcolm Wallace 2006
7 -- License : BSD-style (see the LICENSE file in the distribution)
9 -- Maintainer : libraries@haskell.org
10 -- Stability : experimental
11 -- Portability : portable
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.
18 -- The types for which 'unsafeCoerce' is representation-safe may differ
19 -- from compiler to compiler (and version to version).
21 -- * Documentation for correct usage in GHC will be found under
22 -- 'unsafeCoerce#' in GHC.Base (around which 'unsafeCoerce' is just a
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.
29 module Unsafe.Coerce (unsafeCoerce) where
31 #if defined(__GLASGOW_HASKELL__)
32 import GHC.Prim (unsafeCoerce#)
33 unsafeCoerce :: a -> b
34 unsafeCoerce = unsafeCoerce#
38 import NonStdUnsafeCoerce (unsafeCoerce)
42 import Hugs.IOExts (unsafeCoerce)