/
list_funcs.hs
65 lines (56 loc) · 1.11 KB
/
list_funcs.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
data List a = Nil | Cons a (List a);
data Boolean = True | False;
data Pair a b = P a b;
data Option a = None | Some a;
x where
compose = \f->\g->\x->f (g x);
unit = \x->Cons x Nil;
rep = \xs-> append xs;
abs = \f-> f Nil;
iterate = \f->\x-> Cons x (iterate f (f x));
fp = \p1->\p2->
case p1 of {
P a1 a2 ->
case p2 of { P b1 b2 -> P (a1 b1) (a2 b2);};
};
map = \f->\xs->
case xs of {
Nil -> Nil;
Cons x1 xs1 -> Cons (f x1) (map f xs1);
};
join = \xs->
case xs of {
Nil -> Nil;
Cons x1 xs1 -> append x1 (join xs1);
};
append = \xs->\ys->
case xs of {
Nil -> ys;
Cons x1 xs1 -> Cons x1 (append xs1 ys);
};
idList = \xs->
case xs of {
Nil -> Nil;
Cons x1 xs1 -> Cons x1 (idList xs1);
};
filter = \p->\xs->
case xs of {
Nil -> Nil;
Cons x xs1 ->
case p x of {
True -> Cons x (filter p xs1);
False -> filter p xs1;
};
};
zip = \p->
case p of {
P xs ys ->
case xs of {
Nil -> Nil;
Cons x1 xs1 ->
case ys of {
Nil -> Nil;
Cons y1 ys1 -> Cons (P x1 y1) (zip (P xs1 ys1));
};
};
};