3 data Pair a b = MkPair a b
4 data LList alpha = Nill | Conss alpha (LList alpha)
5 data Nat = Zero | Succ Nat
6 data Tree x = Leaf x | Node (Tree x) (Tree x)
12 idb :: Boolean -> Boolean
15 swap :: Pair a b -> Pair b a
17 MkPair x y -> MkPair y x
19 bang :: A (A a) -> Boolean
23 neg :: Boolean -> Boolean
28 null :: LList x -> Boolean
36 idl :: LList a -> LList a
38 Conss y ys -> Conss y (idl ys)
44 Succ m -> Succ (idn m)
46 add :: Nat -> Nat -> Nat
49 Succ c -> Succ (add c b)
51 length :: LList a -> Nat
52 length xs = case xs of
54 Conss y ys -> Succ(length ys)
56 before :: LList Nat -> LList Nat
57 before xs = case xs of
59 Conss y ys -> case y of
61 Succ n -> Conss y (before ys)
63 reverse :: LList a -> LList a
64 reverse rs = case rs of
66 Conss y ys -> append (reverse ys) (Conss y Nill)
78 append :: LList a -> LList a -> LList a
79 append xs ys = case xs of
81 Conss z zs -> Conss z (append zs ys)
83 flatten :: Tree alpha -> LList alpha
85 Leaf x -> Conss x Nill
86 Node l r -> append (flatten l) (flatten r)
88 sum :: Tree Nat -> Nat
91 Node l r -> add (sum l) (sum r)
93 suml :: LList Nat -> Nat
95 suml (Conss n ns) = add n (suml ns)
97 map :: (a -> b) -> LList a -> LList b
100 Conss y ys -> Conss (f y) (map f ys)