Source file FMapList.ml
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
open Datatypes
open List0
module Raw =
functor (X:OrderedType.OrderedType) ->
struct
module MX = OrderedType.OrderedTypeFacts(X)
module PX = OrderedType.KeyOrderedType(X)
type key = X.t
type 'elt t = (X.t * 'elt) list
(** val empty : 'a1 t **)
let empty =
[]
(** val is_empty : 'a1 t -> bool **)
let is_empty = function
| [] -> true
| _ :: _ -> false
(** val mem : key -> 'a1 t -> bool **)
let rec mem k = function
| [] -> false
| p :: l ->
let (k', _) = p in
(match X.compare k k' with
| OrderedType.LT -> false
| OrderedType.EQ -> true
| OrderedType.GT -> mem k l)
(** val find : key -> 'a1 t -> 'a1 option **)
let rec find k = function
| [] -> None
| p :: s' ->
let (k', x) = p in
(match X.compare k k' with
| OrderedType.LT -> None
| OrderedType.EQ -> Some x
| OrderedType.GT -> find k s')
(** val add : key -> 'a1 -> 'a1 t -> 'a1 t **)
let rec add k x s = match s with
| [] -> (k, x) :: []
| p :: l ->
let (k', y) = p in
(match X.compare k k' with
| OrderedType.LT -> (k, x) :: s
| OrderedType.EQ -> (k, x) :: l
| OrderedType.GT -> (k', y) :: (add k x l))
(** val remove : key -> 'a1 t -> 'a1 t **)
let rec remove k s = match s with
| [] -> []
| p :: l ->
let (k', x) = p in
(match X.compare k k' with
| OrderedType.LT -> s
| OrderedType.EQ -> l
| OrderedType.GT -> (k', x) :: (remove k l))
(** val elements : 'a1 t -> 'a1 t **)
let elements m =
m
(** val fold : (key -> 'a1 -> 'a2 -> 'a2) -> 'a1 t -> 'a2 -> 'a2 **)
let rec fold f m acc =
match m with
| [] -> acc
| p :: m' -> let (k, e) = p in fold f m' (f k e acc)
(** val equal : ('a1 -> 'a1 -> bool) -> 'a1 t -> 'a1 t -> bool **)
let rec equal cmp m m' =
match m with
| [] -> (match m' with
| [] -> true
| _ :: _ -> false)
| p :: l ->
let (x, e) = p in
(match m' with
| [] -> false
| p0 :: l' ->
let (x', e') = p0 in
(match X.compare x x' with
| OrderedType.EQ -> (&&) (cmp e e') (equal cmp l l')
| _ -> false))
(** val map : ('a1 -> 'a2) -> 'a1 t -> 'a2 t **)
let rec map f = function
| [] -> []
| p :: m' -> let (k, e) = p in (k, (f e)) :: (map f m')
(** val mapi : (key -> 'a1 -> 'a2) -> 'a1 t -> 'a2 t **)
let rec mapi f = function
| [] -> []
| p :: m' -> let (k, e) = p in (k, (f k e)) :: (mapi f m')
(** val option_cons :
key -> 'a1 option -> (key * 'a1) list -> (key * 'a1) list **)
let option_cons k o l =
match o with
| Some e -> (k, e) :: l
| None -> l
(** val map2_l :
('a1 option -> 'a2 option -> 'a3 option) -> 'a1 t -> 'a3 t **)
let rec map2_l f = function
| [] -> []
| p :: l -> let (k, e) = p in option_cons k (f (Some e) None) (map2_l f l)
(** val map2_r :
('a1 option -> 'a2 option -> 'a3 option) -> 'a2 t -> 'a3 t **)
let rec map2_r f = function
| [] -> []
| p :: l' ->
let (k, e') = p in option_cons k (f None (Some e')) (map2_r f l')
(** val map2 :
('a1 option -> 'a2 option -> 'a3 option) -> 'a1 t -> 'a2 t -> 'a3 t **)
let rec map2 f m = match m with
| [] -> map2_r f
| p :: l ->
let (k, e) = p in
let rec map2_aux m' = match m' with
| [] -> map2_l f m
| p0 :: l' ->
let (k', e') = p0 in
(match X.compare k k' with
| OrderedType.LT -> option_cons k (f (Some e) None) (map2 f l m')
| OrderedType.EQ -> option_cons k (f (Some e) (Some e')) (map2 f l l')
| OrderedType.GT -> option_cons k' (f None (Some e')) (map2_aux l'))
in map2_aux
(** val combine : 'a1 t -> 'a2 t -> ('a1 option * 'a2 option) t **)
let rec combine m = match m with
| [] -> map (fun e' -> (None, (Some e')))
| p :: l ->
let (k, e) = p in
let rec combine_aux m' = match m' with
| [] -> map (fun e0 -> ((Some e0), None)) m
| p0 :: l' ->
let (k', e') = p0 in
(match X.compare k k' with
| OrderedType.LT -> (k, ((Some e), None)) :: (combine l m')
| OrderedType.EQ -> (k, ((Some e), (Some e'))) :: (combine l l')
| OrderedType.GT -> (k', (None, (Some e'))) :: (combine_aux l'))
in combine_aux
(** val fold_right_pair :
('a1 -> 'a2 -> 'a3 -> 'a3) -> ('a1 * 'a2) list -> 'a3 -> 'a3 **)
let fold_right_pair f l i =
fold_right (fun p -> f (fst p) (snd p)) i l
(** val map2_alt :
('a1 option -> 'a2 option -> 'a3 option) -> 'a1 t -> 'a2 t ->
(key * 'a3) list **)
let map2_alt f m m' =
let m0 = combine m m' in
let m1 = map (fun p -> f (fst p) (snd p)) m0 in
fold_right_pair option_cons m1 []
(** val at_least_one :
'a1 option -> 'a2 option -> ('a1 option * 'a2 option) option **)
let at_least_one o o' =
match o with
| Some _ -> Some (o, o')
| None -> (match o' with
| Some _ -> Some (o, o')
| None -> None)
(** val at_least_one_then_f :
('a1 option -> 'a2 option -> 'a3 option) -> 'a1 option -> 'a2 option ->
'a3 option **)
let at_least_one_then_f f o o' =
match o with
| Some _ -> f o o'
| None -> (match o' with
| Some _ -> f o o'
| None -> None)
end