[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / compiler / tests / stranal / sim.lhs
1 > data Boolean = FF | TT
2 > data Pair a b = MkPair a b
3 > data LList alpha = Nill | Conss alpha (LList alpha) 
4 > data Nat = Zero | Succ Nat
5 > data Tree x = Leaf x | Node (Tree x) (Tree x) 
6 > data A a = MkA a (A a) 
7 >{-
8 > id :: a -> a
9 > id x = x      
10 >
11 > idb :: Boolean -> Boolean
12 > idb b = b
13 >
14 > swap :: Pair a b -> Pair b a
15 > swap t = case t of 
16 >            MkPair x y -> MkPair y x
17 >
18 > bang :: A (A a) -> Boolean
19 > bang x = case x of
20 >            MkA y ys -> TT
21 >
22 > neg :: Boolean -> Boolean
23 > neg b = case b of 
24 >          FF -> TT 
25 >          TT -> FF 
26 >
27 > null :: LList x -> Boolean
28 > null l = case l of 
29 >            Nill -> TT
30 >            _ -> FF
31 >
32 > loop :: Boolean -> a
33 > loop b = loop b
34 >-}
35 > idl ::  LList a -> LList a
36 > idl xs  = case xs of
37 >            Conss y ys -> Conss y (idl ys)
38 >            _ -> Nill 
39 >{-
40 > idn :: Nat -> Nat
41 > idn n = case n of
42 >           Zero -> Zero 
43 >           Succ m -> Succ (idn m)
44 >
45 > add :: Nat -> Nat -> Nat
46 > add a b = case a of 
47 >             Zero -> b
48 >             Succ c -> Succ (add c b) 
49 >
50 > length :: LList a -> Nat
51 > length xs = case xs of 
52 >               Nill -> Zero
53 >               Conss y ys  -> Succ(length ys) 
54 >
55 > before :: LList Nat -> LList Nat
56 > before xs = case xs of
57 >               Nill -> Nill
58 >               Conss y ys -> case y of 
59 >                              Zero -> Nill
60 >                              Succ n -> Conss y (before ys)     
61 >
62 > reverse :: LList a -> LList a
63 > reverse rs = case rs of
64 >                Nill -> Nill
65 >                Conss y ys -> append (reverse ys) (Conss y Nill) 
66 >
67 > f :: Nat -> Nat
68 > f n = case n of
69 >         Zero -> Zero
70 >         Succ m -> Succ (g m)
71 >
72 > g :: Nat -> Nat
73 > g n = case n of
74 >        Zero -> Zero
75 >        Succ m -> Succ (f m)
76 >
77 > append :: LList a -> LList a -> LList a
78 > append  xs ys  = case xs of
79 >                   Nill -> ys 
80 >                   Conss z zs  -> Conss z (append zs ys) 
81 >
82 > flatten :: Tree alpha -> LList alpha
83 > flatten t = case t of
84 >               Leaf x   -> Conss x Nill 
85 >               Node l r -> append (flatten l) (flatten r)
86 >
87 > sum :: Tree Nat -> Nat
88 > sum t = case t of
89 >           Leaf t   -> t
90 >           Node l r -> add (sum l) (sum r) 
91 >
92 > suml :: LList Nat -> Nat
93 > suml Nill = Zero
94 > suml (Conss n ns) = add n (suml ns)
95 >
96 > map :: (a -> b) -> LList a -> LList b
97 > map f xs = case xs of
98 >              Nill -> Nill
99 >              Conss y ys -> Conss (f y) (map f ys)
100 >-}
101
102