c40704da8cff491350f827ba743edc35150f583a
[packages/base.git] / System / Mem / StableName.hs
1 -----------------------------------------------------------------------------
2 --
3 -- Module : System.Mem.StableName
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/core/LICENSE)
6 --
7 -- Maintainer : libraries@haskell.org
8 -- Stability : experimental
9 -- Portability : non-portable
10 --
11 -- $Id: StableName.hs,v 1.3 2001/12/21 15:07:26 simonmar Exp $
12 --
13 -- Giving an object a stable (GC-invariant) name.
14 --
15 -----------------------------------------------------------------------------
16
17 module System.Mem.StableName
18 ( StableName {-a-} -- abstract, instance of Eq
19 , makeStableName -- :: a -> IO (StableName a)
20 , hashStableName -- :: StableName a -> Int
21 ) where
22
23 import Prelude
24
25 import Data.Dynamic
26
27 #ifdef __GLASGOW_HASKELL__
28 import GHC.IOBase ( IO(..) )
29 import GHC.Base ( Int(..), StableName#, makeStableName#
30 , eqStableName#, stableNameToInt# )
31
32 -----------------------------------------------------------------------------
33 -- Stable Names
34
35 data StableName a = StableName (StableName# a)
36
37 makeStableName :: a -> IO (StableName a)
38 #if defined(__PARALLEL_HASKELL__)
39 makeStableName a =
40 error "makeStableName not implemented in parallel Haskell"
41 #else
42 makeStableName a = IO $ \ s ->
43 case makeStableName# a s of (# s', sn #) -> (# s', StableName sn #)
44 #endif
45
46 hashStableName :: StableName a -> Int
47 #if defined(__PARALLEL_HASKELL__)
48 hashStableName (StableName sn) =
49 error "hashStableName not implemented in parallel Haskell"
50 #else
51 hashStableName (StableName sn) = I# (stableNameToInt# sn)
52 #endif
53
54 instance Eq (StableName a) where
55 #if defined(__PARALLEL_HASKELL__)
56 (StableName sn1) == (StableName sn2) =
57 error "eqStableName not implemented in parallel Haskell"
58 #else
59 (StableName sn1) == (StableName sn2) =
60 case eqStableName# sn1 sn2 of
61 0# -> False
62 _ -> True
63 #endif
64
65 #endif /* __GLASGOW_HASKELL__ */
66
67 #include "Dynamic.h"
68 INSTANCE_TYPEABLE1(StableName,stableNameTc,"StableName")