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.2 2001/09/13 11:37:08 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.Base ( Int(..) )
29 import GHC.IOBase ( IO(..) )
30 import GHC.Prim ( StableName#, makeStableName#
31 , eqStableName#, stableNameToInt# )
33 -----------------------------------------------------------------------------
36 data StableName a = StableName (StableName# a)
38 makeStableName :: a -> IO (StableName a)
39 #if defined(__PARALLEL_HASKELL__)
41 error "makeStableName not implemented in parallel Haskell"
43 makeStableName a = IO $ \ s ->
44 case makeStableName# a s of (# s', sn #) -> (# s', StableName sn #)
47 hashStableName :: StableName a -> Int
48 #if defined(__PARALLEL_HASKELL__)
49 hashStableName (StableName sn) =
50 error "hashStableName not implemented in parallel Haskell"
52 hashStableName (StableName sn) = I# (stableNameToInt# sn)
55 instance Eq (StableName a) where
56 #if defined(__PARALLEL_HASKELL__)
57 (StableName sn1) == (StableName sn2) =
58 error "eqStableName not implemented in parallel Haskell"
60 (StableName sn1) == (StableName sn2) =
61 case eqStableName# sn1 sn2 of
66 #endif /* __GLASGOW_HASKELL__ */
69 INSTANCE_TYPEABLE1(StableName,stableNameTc,"StableName")