a a12
[ap2015.git] / a12 / mart / skeleton12.icl
1 module skeleton12
2
3 import Data.Maybe
4 import Control.Monad
5 import StdInt, StdString, StdBool
6
7 class arith x where
8 lit :: a -> x a | toString a
9 (+.) infixl 6 :: (x a) (x a) -> x a | + a // integer addition, Boolean OR
10 (*.) infixl 7 :: (x a) (x a) -> x a | * a // integer multiplication, Boolean AND
11 class store x where
12 read :: (x Int)
13 write :: (x Int) -> x Int
14 class truth x where
15 (XOR) infixr 3 :: (x Bool) (x Bool) -> x Bool
16 -. :: (x Bool) -> x Bool
17 class (=.=) infix 4 x :: (x a) (x a) -> x Bool | == a
18 class except x where
19 throw :: (x a)
20 try :: (x a) (x a) -> x a
21
22 class aexpr x | arith, store, except, =.= x
23 class bexpr x | arith, truth, except, =.= x
24 class expr x | aexpr, bexpr x
25
26 :: Step a = Step (State -> (Maybe a, State))
27 :: State :== Int
28
29 /*seven :: e Int | aexpr e
30 seven = lit 3 +. lit 4
31
32 throw1 :: e Int | expr e
33 throw1 = lit 3 +. throw
34
35 six :: e Int | expr e
36 six = write (lit 3) +. read
37
38 try1 :: e Int | expr e
39 try1 = try throw1 (lit 42)
40
41 loge :: e Bool | expr e
42 loge = lit True *. -. (lit True)
43
44 comp :: e Bool | expr e
45 comp = lit 1 =.= lit 2 XOR -. (-. (lit True))*/
46
47 Start = 0