gadt shit
[ap2015.git] / a12 / mart / skeleton12.icl
1 module skeleton12
2
3 import StdEnv
4 import StdMaybe
5
6 :: BM a b = {t :: a -> b, f :: b -> a}
7 bm :: BM a a
8 bm = {f=id, t=id}
9 :: Expr a
10 = Lit a
11 | (+.) infixl 6 (Expr a) (Expr a)
12 | (*.) infixl 6 (Expr a) (Expr a)
13 | Read
14 | Write (Expr Int)
15 | XOR (Expr Bool) (Expr Bool)
16 | Not (Expr Bool)
17 | E.b: Eq (Expr b) ( Expr b) & == b
18 | Throw
19 | Try (Expr a) (Expr a)
20
21 class show a :: a [String] -> [String]
22 instance show (Expr a) where
23 show (Lit x) l = [toString x:l]
24 show (x1 +. x2) l = show x1 ["+":show x2 l]
25 show (x1 *. x2) l = show x1 ["*":show x2 l]
26 show Read l = ["Read":l]
27 show (Write x) l = ["Write (":show x [")":l]]
28 show (XOR x1 x2) l = show x1 ["XOR":show x2 l]
29 show (Not x) l = ["Not":show x l]
30 show (Eq x1 x2) l = show x1 ["==":show x2 l]
31 show Throw l = ["throw":l]
32 show (Try x1 x2) l = ["Try":show x1 ["Except":show x2 l]]