/usr/lib/hugs/packages/hugsbase/Hugs/LazyST.hs is in hugs 98.200609.21-5.3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | -----------------------------------------------------------------------------
-- Lazy State Thread module
--
-- This library provides support for both lazy and strict state threads,
-- as described in the PLDI '94 paper by John Launchbury and Simon Peyton
-- Jones. In addition to the monad ST, it also provides mutable variables
-- STRef and mutable arrays STArray. It is identical to the ST module
-- except that the ST instance is lazy.
--
-- Suitable for use with Hugs 98.
-----------------------------------------------------------------------------
module Hugs.LazyST
( ST
, runST
, unsafeInterleaveST
, fixST
, lazyToStrictST
, strictToLazyST
) where
import qualified Hugs.ST as ST
import Control.Monad
-----------------------------------------------------------------------------
newtype ST s a = ST (State s -> (a, State s))
unST :: ST s a -> State s -> (a, State s)
unST (ST f) = f
runST :: (forall s. ST s a) -> a
runST m = fst (unST m S)
unsafeInterleaveST :: ST s a -> ST s a
unsafeInterleaveST (ST m) = return (fst (m S))
fixST :: (a -> ST s a) -> ST s a
fixST f = ST (\s -> let (x,s') = unST (f x) s in (x,s'))
instance Functor (ST s) where
fmap = liftM
instance Monad (ST s) where
return a = ST (\s -> (a, s))
ST m >>= f = ST (\S -> let (a,s') = m S in unST (f a) s')
-- ST m >>= f = ST (\s -> let (a,s') = m s in unST (f a) s')
-----------------------------------------------------------------------------
data State s = S
-----------------------------------------------------------------------------
lazyToStrictST :: ST s a -> ST.ST s a
lazyToStrictST (ST m) = ST.ST (\k -> case m S of (a,S) -> k a)
strictToLazyST :: ST.ST s a -> ST s a
strictToLazyST (ST.ST m) = ST (\S -> m delay)
-- \s -> let (a',s') = case s of S -> m (\a -> (a,S)) in (a',s'))
delay :: a -> (a, State s)
delay a = (a,S)
-----------------------------------------------------------------------------
|