1 -- $Id: Cpr001_imp.hs,v 1.1 2001/03/28 05:07:34 kglynn Exp $
3 module Cpr001_imp where
5 data MS = MS { instr :: String
10 , status :: Maybe String
14 newtype StateTrans s a = ST ( s -> (s, Maybe a))
16 -- state monad with error handling
17 -- in case of an error, the state remains
18 -- as it is and Nothing is returned as value
19 -- else execution continues
21 instance Monad (StateTrans s) where
31 Nothing -> (s1, Nothing)
34 = ST (\s -> (s, Just v))
37 -- machine state transitions
39 type MachineStateTrans = StateTrans MS
41 type MST = MachineStateTrans
43 {-# NOINLINE setMTerminated #-}
45 = ST (\ms -> (ms { status = Just "Terminated" }, Just ()))
48 = ST (\ms -> (ms { status = Just "Service" }, Just ()))
50 -- -------------------------------------------------------------------
53 = LoadI Int -- load int const
54 | SysCall String -- system call (svc)