1 -----------------------------------------------------------------------------
3 -- Module : System.Mem.StableName
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/core/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : experimental
9 -- Portability : non-portable
11 -- $Id: StableName.hs,v 1.3 2001/12/21 15:07:26 simonmar Exp $
13 -- Giving an object a stable (GC-invariant) name.
15 -----------------------------------------------------------------------------
17 module System.Mem.StableName
18 ( StableName {-a-} -- abstract, instance of Eq
19 , makeStableName -- :: a -> IO (StableName a)
20 , hashStableName -- :: StableName a -> Int
27 #ifdef __GLASGOW_HASKELL__
28 import GHC.IOBase ( IO(..) )
29 import GHC.Base ( Int(..), StableName#, makeStableName#
30 , eqStableName#, stableNameToInt# )
32 -----------------------------------------------------------------------------
35 data StableName a = StableName (StableName# a)
37 makeStableName :: a -> IO (StableName a)
38 #if defined(__PARALLEL_HASKELL__)
40 error "makeStableName not implemented in parallel Haskell"
42 makeStableName a = IO $ \ s ->
43 case makeStableName# a s of (# s', sn #) -> (# s', StableName sn #)
46 hashStableName :: StableName a -> Int
47 #if defined(__PARALLEL_HASKELL__)
48 hashStableName (StableName sn) =
49 error "hashStableName not implemented in parallel Haskell"
51 hashStableName (StableName sn) = I# (stableNameToInt# sn)
54 instance Eq (StableName a) where
55 #if defined(__PARALLEL_HASKELL__)
56 (StableName sn1) == (StableName sn2) =
57 error "eqStableName not implemented in parallel Haskell"
59 (StableName sn1) == (StableName sn2) =
60 case eqStableName# sn1 sn2 of
65 #endif /* __GLASGOW_HASKELL__ */
68 INSTANCE_TYPEABLE1(StableName,stableNameTc,"StableName")