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
| let rec count (l, x) =
match l with
| [] -> 0
| l::ls when l = x -> 1 + count(ls, x)
| _::ls -> count(ls, x)
let rec insert (l, x) =
match l with
| [] -> []
| l::ls when x <= l -> x::ls
| l::ls -> l::insert(ls, x)
let rec intersect = function
| [], _ | _, [] -> []
| x::xs, y::ys when x = y -> x :: intersect (xs, ys)
| x::xs, y::ys when x < y -> intersect (xs, y::ys)
| x::xs, _::ys -> intersect (x::xs, ys)
let rec plus = function
| [], ys -> ys
| xs, [] -> xs
| x::xs, y::ys when x <= y -> x :: plus (xs, y::ys)
| xs, y::ys -> y :: plus (xs, ys)
let rec minus = function
| [], _ -> []
| xs, [] -> xs
| x::xs, y::ys when x = y -> minus (xs, ys)
| x::xs, y::ys when x < y -> x :: minus(xs, y::ys)
| x::xs, _::ys -> minus(x::xs, ys)
|