[project @ 1999-01-26 12:24:57 by simonm]
[ghc-hetmet.git] / ghc / lib / exts / Stable.lhs
1 % -----------------------------------------------------------------------------
2 % $Id: Stable.lhs,v 1.1 1999/01/26 12:24:58 simonm Exp $
3 %
4 % (c) The GHC Team, 1999
5 %
6
7 \section[Stable]{Module @Stable@}
8
9 \begin{code}
10 module Stable
11
12         ( StableName {-a-}      -- abstract.
13         , makeStableName        -- :: a -> IO (StableName a)
14         , hashStableName        -- :: StableName a -> Int
15
16         , StablePtr {-a-}       -- abstract.
17         , makeStablePtr         -- :: a -> IO (StablePtr a)
18         , deRefStablePtr        -- :: StablePtr a -> IO a
19         , freeStablePtr         -- :: StablePtr a -> IO ()
20         )
21
22   where
23
24 import PrelBase
25 import PrelIOBase
26 import PrelStable
27
28 -----------------------------------------------------------------------------
29 -- Stable Names
30
31 data StableName a = StableName (StableName# a)
32
33 makeStableName  :: a -> IO (StableName a)
34 hashStableName :: StableName a -> Int
35
36 makeStableName a = IO $ \ s ->
37     case makeStableName# a s of (# s', sn #) -> (# s', StableName sn #)
38
39 hashStableName (StableName sn) = I# (stableNameToInt# sn)
40
41 instance Eq (StableName a) where 
42     (StableName sn1) == (StableName sn2) = 
43        case eqStableName# sn1 sn2 of
44          0# -> False
45          _  -> True
46
47 \end{code}