1 {-# OPTIONS_GHC -XNoImplicitPrelude #-}
2 -----------------------------------------------------------------------------
4 -- Module : Unsafe.Coerce
5 -- Copyright : Malcolm Wallace 2006
6 -- License : BSD-style (see the LICENSE file in the distribution)
8 -- Maintainer : libraries@haskell.org
9 -- Stability : experimental
10 -- Portability : portable
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.
17 -- The types for which 'unsafeCoerce' is representation-safe may differ
18 -- from compiler to compiler (and version to version).
20 -- * Documentation for correct usage in GHC will be found under
21 -- 'unsafeCoerce#' in GHC.Base (around which 'unsafeCoerce' is just a
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.
28 module Unsafe.Coerce (unsafeCoerce) where
30 #if defined(__GLASGOW_HASKELL__)
31 import GHC.Base (unsafeCoerce#)
32 unsafeCoerce :: a -> b
33 unsafeCoerce = unsafeCoerce#
37 import NonStdUnsafeCoerce (unsafeCoerce)
41 import Hugs.IOExts (unsafeCoerce)