blob: 4c226c9d13e74b58dccff8edee1aba7e96259005 (
plain) (
blame)
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
|
implementation module Simple
import StdString
import WhileCommon
import Common
instance toString Stm
where
toString (Ass v a) = v <+ " := " <+ a
toString (If b s1 s2) = "if " <+ b <+ " then " <+ s1 <+ " else " <+ s2
toString (While b s) = "while " <+ b <+ " do " <+ s
toString Skip = "skip"
toString (Compose s1 s2) = s1 <+ "; " <+ s2
instance run Stm
where
run (Ass v e) st
= pure (\w -> if (w==v) (eval e st) (st w))
run (If b s1 s2) st
= eval b st >>= \r -> run (if r s1 s2) st
run w=:(While b s) st
= eval b st >>= \r -> if r
(run s st >>= run w)
(pure st)
run Skip st
= pure st
run (Compose s1 s2) st
= run s1 st >>= run s2
|