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)
11 > idb :: Boolean -> Boolean
14 > swap :: Pair a b -> Pair b a
16 > MkPair x y -> MkPair y x
18 > bang :: A (A a) -> Boolean
22 > neg :: Boolean -> Boolean
27 > null :: LList x -> Boolean
32 > loop :: Boolean -> a
35 > idl :: LList a -> LList a
37 > Conss y ys -> Conss y (idl ys)
43 > Succ m -> Succ (idn m)
45 > add :: Nat -> Nat -> Nat
48 > Succ c -> Succ (add c b)
50 > length :: LList a -> Nat
51 > length xs = case xs of
53 > Conss y ys -> Succ(length ys)
55 > before :: LList Nat -> LList Nat
56 > before xs = case xs of
58 > Conss y ys -> case y of
60 > Succ n -> Conss y (before ys)
62 > reverse :: LList a -> LList a
63 > reverse rs = case rs of
65 > Conss y ys -> append (reverse ys) (Conss y Nill)
70 > Succ m -> Succ (g m)
75 > Succ m -> Succ (f m)
77 > append :: LList a -> LList a -> LList a
78 > append xs ys = case xs of
80 > Conss z zs -> Conss z (append zs ys)
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)
87 > sum :: Tree Nat -> Nat
90 > Node l r -> add (sum l) (sum r)
92 > suml :: LList Nat -> Nat
94 > suml (Conss n ns) = add n (suml ns)
96 > map :: (a -> b) -> LList a -> LList b
97 > map f xs = case xs of
99 > Conss y ys -> Conss (f y) (map f ys)