[project @ 2001-06-28 14:15:04 by simonmar]
[ghc-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.1 2001/06/28 14:15:04 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 #ifdef __GLASGOW_HASKELL__
26 import GHC.Base         ( Int(..) )
27 import GHC.IOBase       ( IO(..) )
28 import GHC.Prim         ( StableName#, makeStableName#
29                         , eqStableName#, stableNameToInt# )
30
31 -----------------------------------------------------------------------------
32 -- Stable Names
33
34 data StableName a = StableName (StableName# a)
35
36 makeStableName  :: a -> IO (StableName a)
37 #if defined(__PARALLEL_HASKELL__)
38 makeStableName a = 
39   error "makeStableName not implemented in parallel Haskell"
40 #else
41 makeStableName a = IO $ \ s ->
42     case makeStableName# a s of (# s', sn #) -> (# s', StableName sn #)
43 #endif
44
45 hashStableName :: StableName a -> Int
46 #if defined(__PARALLEL_HASKELL__)
47 hashStableName (StableName sn) = 
48   error "hashStableName not implemented in parallel Haskell"
49 #else
50 hashStableName (StableName sn) = I# (stableNameToInt# sn)
51 #endif
52
53 instance Eq (StableName a) where 
54 #if defined(__PARALLEL_HASKELL__)
55     (StableName sn1) == (StableName sn2) = 
56       error "eqStableName not implemented in parallel Haskell"
57 #else
58     (StableName sn1) == (StableName sn2) = 
59        case eqStableName# sn1 sn2 of
60          0# -> False
61          _  -> True
62 #endif
63
64 #endif /* __GLASGOW_HASKELL__ */
65
66 #include "Dynamic.h"
67 INSTANCE_TYPEABLE1(StableName,stableNameTc,"StableName")