Commit | Line | Data |
---|---|---|
34e49164 C |
1 | (*###########################################################################*) |
2 | (* Globals *) | |
3 | (*###########################################################################*) | |
4 | ||
5 | (* Some conventions: | |
6 | * | |
7 | * When I have some _xxx variables before some functions, it's | |
8 | * because I want to show that those functions internally use a global | |
9 | * variable. That does not mean I want people to modify this global. | |
10 | * In fact they are kind of private, but I still want to show them. | |
11 | * Maybe one day OCaml will have an effect type system so I don't need this. | |
12 | * | |
13 | * The variables that are called _init_xxx show the internal init | |
14 | * side effect of the module (like static var trick used in C/C++) | |
15 | * | |
16 | * Why not split the functionnalities of this file in different files ? | |
17 | * Because when I write ocaml script I want simply to load one | |
18 | * file, common.ml, and that's it. Cf common_extra.ml for more on this. | |
19 | *) | |
20 | ||
21 | ||
22 | (*****************************************************************************) | |
23 | (* Flags *) | |
24 | (*****************************************************************************) | |
25 | (* see the corresponding section for the use of those flags. See also | |
26 | * the "Flags and actions" section at the end of this file. | |
27 | *) | |
28 | ||
29 | (* if set then will not do certain finalize so faster to go back in replay *) | |
30 | val debugger : bool ref | |
31 | ||
32 | type prof = PALL | PNONE | PSOME of string list | |
33 | val profile : prof ref | |
485bce71 C |
34 | val show_trace_profile : bool ref |
35 | ||
34e49164 C |
36 | |
37 | val verbose_level : int ref | |
38 | ||
39 | (* forbid pr2_once to do the once "optimisation" *) | |
40 | val disable_pr2_once : bool ref | |
41 | ||
42 | ||
43 | ||
44 | (* works with new_temp_file *) | |
45 | val save_tmp_files : bool ref | |
46 | ||
47 | ||
48 | ||
49 | (*****************************************************************************) | |
50 | (* Module side effect *) | |
51 | (*****************************************************************************) | |
52 | (* | |
53 | * I define a few unit tests via some let _ = example (... = ...). | |
54 | * I also initialize the random seed, cf _init_random . | |
55 | * I also set Gc.stack_size, cf _init_gc_stack . | |
56 | *) | |
57 | ||
58 | (*****************************************************************************) | |
59 | (* Semi globals *) | |
60 | (*****************************************************************************) | |
61 | (* cf the _xxx variables in this file *) | |
62 | ||
63 | (*###########################################################################*) | |
64 | (* Basic features *) | |
65 | (*###########################################################################*) | |
66 | ||
67 | type filename = string | |
485bce71 | 68 | type dirname = string |
34e49164 C |
69 | |
70 | (* Trick in case you dont want to do an 'open Common' while still wanting | |
71 | * more pervasive types than the one in Pervasives. Just do the selective | |
72 | * open Common.BasicType. | |
73 | *) | |
74 | module BasicType : sig | |
75 | type filename = string | |
76 | end | |
77 | ||
78 | (* Same spirit. Trick found in Jane Street core lib, but originated somewhere | |
79 | * else I think: the ability to open nested modules. *) | |
80 | module Infix : sig | |
81 | val ( +> ) : 'a -> ('a -> 'b) -> 'b | |
82 | val ( =~ ) : string -> string -> bool | |
83 | val ( ==~ ) : string -> Str.regexp -> bool | |
84 | end | |
85 | ||
86 | ||
87 | (* | |
88 | * Another related trick, found via Jon Harrop to have an extended standard | |
89 | * lib is to do something like | |
90 | * | |
91 | * module List = struct | |
92 | * include List | |
93 | * val map2 : ... | |
94 | * end | |
95 | * | |
96 | * And then can put this "module extension" somewhere to open it. | |
97 | *) | |
98 | ||
99 | ||
100 | ||
101 | (* This module defines the Timeout and UnixExit exceptions. | |
102 | * You have to make sure that those exn are not intercepted. So | |
103 | * avoid exn handler such as try (...) with _ -> cos Timeout will not bubble up | |
104 | * enough. In such case, add a case before such as | |
105 | * with Timeout -> raise Timeout | _ -> ... | |
106 | * The same is true for UnixExit (see below). | |
107 | *) | |
108 | ||
109 | (*****************************************************************************) | |
110 | (* Debugging/logging *) | |
111 | (*****************************************************************************) | |
112 | ||
113 | val _tab_level_print: int ref | |
114 | val indent_do : (unit -> 'a) -> 'a | |
115 | val reset_pr_indent : unit -> unit | |
116 | ||
117 | (* The following functions first indent _tab_level_print spaces. | |
118 | * They also add the _prefix_pr, for instance used in MPI to show which | |
119 | * worker is talking. | |
708f4980 | 120 | * update: for pr2, it can also print into a log file. |
34e49164 C |
121 | * |
122 | * The use of 2 in pr2 is because 2 is under UNIX the second descriptor | |
123 | * which corresponds to stderr. | |
124 | *) | |
125 | val _prefix_pr : string ref | |
708f4980 | 126 | |
34e49164 | 127 | val pr : string -> unit |
34e49164 | 128 | val pr_no_nl : string -> unit |
34e49164 | 129 | val pr_xxxxxxxxxxxxxxxxx : unit -> unit |
708f4980 C |
130 | |
131 | (* pr2 print on stderr, but can also in addition print into a file *) | |
132 | val _chan_pr2: out_channel option ref | |
133 | val pr2 : string -> unit | |
134 | val pr2_no_nl : string -> unit | |
34e49164 C |
135 | val pr2_xxxxxxxxxxxxxxxxx : unit -> unit |
136 | ||
137 | (* use Dumper.dump *) | |
138 | val pr2_gen: 'a -> unit | |
139 | val dump: 'a -> string | |
140 | ||
141 | (* see flag: val disable_pr2_once : bool ref *) | |
142 | val _already_printed : (string, bool) Hashtbl.t | |
143 | val pr2_once : string -> unit | |
144 | ||
708f4980 C |
145 | val mk_pr2_wrappers: bool ref -> (string -> unit) * (string -> unit) |
146 | ||
147 | ||
34e49164 C |
148 | val redirect_stdout_stderr : filename -> (unit -> unit) -> unit |
149 | val redirect_stdin : filename -> (unit -> unit) -> unit | |
150 | val redirect_stdin_opt : filename option -> (unit -> unit) -> unit | |
151 | ||
708f4980 C |
152 | val with_pr2_to_string: (unit -> unit) -> string list |
153 | ||
34e49164 C |
154 | val fprintf : out_channel -> ('a, out_channel, unit) format -> 'a |
155 | val printf : ('a, out_channel, unit) format -> 'a | |
156 | val eprintf : ('a, out_channel, unit) format -> 'a | |
157 | val sprintf : ('a, unit, string) format -> 'a | |
158 | ||
159 | (* alias *) | |
160 | val spf : ('a, unit, string) format -> 'a | |
161 | ||
162 | (* default = stderr *) | |
163 | val _chan : out_channel ref | |
164 | (* generate & use a /tmp/debugml-xxx file *) | |
165 | val start_log_file : unit -> unit | |
166 | ||
167 | (* see flag: val verbose_level : int ref *) | |
168 | val log : string -> unit | |
169 | val log2 : string -> unit | |
170 | val log3 : string -> unit | |
171 | val log4 : string -> unit | |
172 | ||
173 | val if_log : (unit -> unit) -> unit | |
174 | val if_log2 : (unit -> unit) -> unit | |
175 | val if_log3 : (unit -> unit) -> unit | |
176 | val if_log4 : (unit -> unit) -> unit | |
177 | ||
178 | val pause : unit -> unit | |
179 | ||
180 | (* was used by fix_caml *) | |
181 | val _trace_var : int ref | |
182 | val add_var : unit -> unit | |
183 | val dec_var : unit -> unit | |
184 | val get_var : unit -> int | |
185 | ||
186 | val print_n : int -> string -> unit | |
187 | val printerr_n : int -> string -> unit | |
188 | ||
189 | val _debug : bool ref | |
190 | val debugon : unit -> unit | |
191 | val debugoff : unit -> unit | |
192 | val debug : (unit -> unit) -> unit | |
193 | ||
194 | (* see flag: val debugger : bool ref *) | |
195 | ||
196 | ||
197 | (*****************************************************************************) | |
198 | (* Profiling (cpu/mem) *) | |
199 | (*****************************************************************************) | |
200 | ||
201 | val get_mem : unit -> unit | |
202 | val memory_stat : unit -> string | |
203 | ||
204 | val timenow : unit -> string | |
205 | ||
206 | val _count1 : int ref | |
207 | val _count2 : int ref | |
208 | val _count3 : int ref | |
209 | val _count4 : int ref | |
210 | val _count5 : int ref | |
211 | ||
212 | val count1 : unit -> unit | |
213 | val count2 : unit -> unit | |
214 | val count3 : unit -> unit | |
215 | val count4 : unit -> unit | |
216 | val count5 : unit -> unit | |
217 | val profile_diagnostic_basic : unit -> string | |
218 | ||
219 | val time_func : (unit -> 'a) -> 'a | |
220 | ||
221 | ||
222 | ||
223 | (* see flag: type prof = PALL | PNONE | PSOME of string list *) | |
224 | (* see flag: val profile : prof ref *) | |
225 | ||
226 | val _profile_table : (string, (float ref * int ref)) Hashtbl.t ref | |
227 | val profile_code : string -> (unit -> 'a) -> 'a | |
228 | val profile_diagnostic : unit -> string | |
229 | ||
485bce71 C |
230 | val profile_code_exclusif : string -> (unit -> 'a) -> 'a |
231 | val profile_code_inside_exclusif_ok : string -> (unit -> 'a) -> 'a | |
232 | ||
34e49164 C |
233 | val report_if_take_time : int -> string -> (unit -> 'a) -> 'a |
234 | ||
235 | (* similar to profile_code but print some information during execution too *) | |
236 | val profile_code2 : string -> (unit -> 'a) -> 'a | |
237 | ||
238 | (*****************************************************************************) | |
239 | (* Test *) | |
240 | (*****************************************************************************) | |
241 | ||
242 | val example : bool -> unit | |
243 | (* generate failwith <string> when pb *) | |
244 | val example2 : string -> bool -> unit | |
245 | (* use Dumper to report when pb *) | |
246 | val assert_equal : 'a -> 'a -> unit | |
247 | ||
248 | val _list_bool : (string * bool) list ref | |
249 | val example3 : string -> bool -> unit | |
250 | val test_all : unit -> unit | |
251 | ||
b1b2de81 | 252 | |
34e49164 C |
253 | (* regression testing *) |
254 | type score_result = Ok | Pb of string | |
b1b2de81 C |
255 | type score = (string (* usually a filename *), score_result) Hashtbl.t |
256 | type score_list = (string (* usually a filename *) * score_result) list | |
34e49164 C |
257 | val empty_score : unit -> score |
258 | val regression_testing : | |
259 | score -> filename (* old score file on disk (usually in /tmp) *) -> unit | |
b1b2de81 C |
260 | val regression_testing_vs: score -> score -> score |
261 | val total_scores : score -> int (* good *) * int (* total *) | |
34e49164 | 262 | val print_score : score -> unit |
b1b2de81 | 263 | val print_total_score: score -> unit |
34e49164 C |
264 | |
265 | ||
266 | (* quickcheck spirit *) | |
267 | type 'a gen = unit -> 'a | |
268 | ||
269 | (* quickcheck random generators *) | |
270 | val ig : int gen | |
271 | val lg : 'a gen -> 'a list gen | |
272 | val pg : 'a gen -> 'b gen -> ('a * 'b) gen | |
273 | val polyg : int gen | |
274 | val ng : string gen | |
275 | ||
276 | val oneofl : 'a list -> 'a gen | |
277 | val oneof : 'a gen list -> 'a gen | |
278 | val always : 'a -> 'a gen | |
279 | val frequency : (int * 'a gen) list -> 'a gen | |
280 | val frequencyl : (int * 'a) list -> 'a gen | |
281 | ||
282 | val laws : string -> ('a -> bool) -> 'a gen -> 'a option | |
283 | ||
284 | (* example of use: | |
285 | * let b = laws "unit" (fun x -> reverse [x] = [x]) ig | |
286 | *) | |
287 | ||
288 | val statistic_number : 'a list -> (int * 'a) list | |
289 | val statistic : 'a list -> (int * 'a) list | |
290 | ||
291 | val laws2 : | |
292 | string -> ('a -> bool * 'b) -> 'a gen -> 'a option * (int * 'b) list | |
293 | ||
294 | (*****************************************************************************) | |
295 | (* Persistence *) | |
296 | (*****************************************************************************) | |
297 | ||
0708f913 | 298 | (* just wrappers around Marshal *) |
34e49164 | 299 | val get_value : filename -> 'a |
485bce71 | 300 | val read_value : filename -> 'a (* alias *) |
34e49164 C |
301 | val write_value : 'a -> filename -> unit |
302 | val write_back : ('a -> 'b) -> filename -> unit | |
303 | ||
0708f913 C |
304 | (* wrappers that also use profile_code *) |
305 | val marshal__to_string: 'a -> Marshal.extern_flags list -> string | |
306 | val marshal__from_string: string -> int -> 'a | |
307 | ||
34e49164 C |
308 | (*****************************************************************************) |
309 | (* Counter *) | |
310 | (*****************************************************************************) | |
311 | val _counter : int ref | |
312 | val _counter2 : int ref | |
313 | val _counter3 : int ref | |
314 | ||
315 | val counter : unit -> int | |
316 | val counter2 : unit -> int | |
317 | val counter3 : unit -> int | |
318 | ||
319 | type timestamp = int | |
320 | ||
321 | (*****************************************************************************) | |
322 | (* String_of and (pretty) printing *) | |
323 | (*****************************************************************************) | |
324 | ||
325 | val string_of_string : (string -> string) -> string | |
326 | val string_of_list : ('a -> string) -> 'a list -> string | |
327 | val string_of_unit : unit -> string | |
328 | val string_of_array : ('a -> string) -> 'a array -> string | |
329 | val string_of_option : ('a -> string) -> 'a option -> string | |
330 | ||
331 | val print_bool : bool -> unit | |
332 | val print_option : ('a -> 'b) -> 'a option -> unit | |
333 | val print_list : ('a -> 'b) -> 'a list -> unit | |
334 | val print_between : (unit -> unit) -> ('a -> unit) -> 'a list -> unit | |
335 | ||
336 | (* use Format internally *) | |
337 | val pp_do_in_box : (unit -> unit) -> unit | |
338 | val pp_f_in_box : (unit -> 'a) -> 'a | |
339 | val pp_do_in_zero_box : (unit -> unit) -> unit | |
340 | val pp : string -> unit | |
341 | ||
342 | (* convert something printed using Format to print into a string *) | |
343 | val format_to_string : (unit -> unit) (* printer *) -> string | |
344 | ||
345 | (* works with _tab_level_print enabling to mix some calls to pp, pr2 | |
346 | * and indent_do to sometimes use advanced indentation pretty printing | |
347 | * (with the pp* functions) and sometimes explicit and simple indendation | |
348 | * printing (with pr* and indent_do) *) | |
349 | val adjust_pp_with_indent : (unit -> unit) -> unit | |
350 | val adjust_pp_with_indent_and_header : string -> (unit -> unit) -> unit | |
351 | ||
0708f913 C |
352 | |
353 | val mk_str_func_of_assoc_conv: | |
354 | ('a * string) list -> (string -> 'a) * ('a -> string) | |
355 | ||
34e49164 C |
356 | (*****************************************************************************) |
357 | (* Macro *) | |
358 | (*****************************************************************************) | |
359 | ||
360 | (* was working with my macro.ml4 *) | |
361 | val macro_expand : string -> unit | |
362 | ||
363 | (*****************************************************************************) | |
364 | (* Composition/Control *) | |
365 | (*****************************************************************************) | |
366 | ||
367 | val ( +> ) : 'a -> ('a -> 'b) -> 'b | |
368 | val ( +!> ) : 'a ref -> ('a -> 'a) -> unit | |
369 | val ( $ ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c | |
370 | ||
371 | val compose : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b | |
372 | val flip : ('a -> 'b -> 'c) -> 'b -> 'a -> 'c | |
373 | ||
374 | val curry : ('a * 'b -> 'c) -> 'a -> 'b -> 'c | |
375 | val uncurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c | |
376 | ||
377 | val id : 'a -> 'a | |
378 | val do_nothing : unit -> unit | |
379 | ||
380 | val forever : (unit -> unit) -> unit | |
381 | ||
382 | val applyn : int -> ('a -> 'a) -> 'a -> 'a | |
383 | ||
384 | class ['a] shared_variable_hook : | |
385 | 'a -> | |
386 | object | |
387 | val mutable data : 'a | |
388 | val mutable registered : (unit -> unit) list | |
389 | method get : 'a | |
390 | method modify : ('a -> 'a) -> unit | |
391 | method register : (unit -> unit) -> unit | |
392 | method set : 'a -> unit | |
393 | end | |
394 | ||
395 | val fixpoint : ('a -> 'a) -> 'a -> 'a | |
396 | val fixpoint_for_object : ((< equal : 'a -> bool; .. > as 'a) -> 'a) -> 'a -> 'a | |
397 | ||
398 | val add_hook : ('a -> ('a -> 'b) -> 'b) ref -> ('a -> ('a -> 'b) -> 'b) -> unit | |
399 | val add_hook_action : ('a -> unit) -> ('a -> unit) list ref -> unit | |
400 | val run_hooks_action : 'a -> ('a -> unit) list ref -> unit | |
401 | ||
402 | type 'a mylazy = (unit -> 'a) | |
403 | ||
404 | (* emacs spirit *) | |
405 | val save_excursion : 'a ref -> (unit -> 'b) -> 'b | |
708f4980 C |
406 | val save_excursion_and_disable : bool ref -> (unit -> 'b) -> 'b |
407 | val save_excursion_and_enable : bool ref -> (unit -> 'b) -> 'b | |
34e49164 C |
408 | |
409 | (* emacs spirit *) | |
410 | val unwind_protect : (unit -> 'a) -> (exn -> 'b) -> 'a | |
411 | ||
412 | (* java spirit *) | |
413 | val finalize : (unit -> 'a) -> (unit -> 'b) -> 'a | |
414 | ||
415 | val memoized : ('a, 'b) Hashtbl.t -> 'a -> (unit -> 'b) -> 'b | |
416 | ||
91eba41f C |
417 | val cache_in_ref : 'a option ref -> (unit -> 'a) -> 'a |
418 | ||
34e49164 C |
419 | |
420 | (* take file from which computation is done, an extension, and the function | |
421 | * and will compute the function only once and then save result in | |
422 | * file ^ extension | |
423 | *) | |
424 | val cache_computation : | |
425 | ?verbose:bool -> ?use_cache:bool -> filename -> string (* extension *) -> | |
426 | (unit -> 'a) -> 'a | |
427 | ||
428 | (* a more robust version where the client describes the dependencies of the | |
429 | * computation so it will relaunch the computation in 'f' if needed. | |
430 | *) | |
431 | val cache_computation_robust : | |
432 | filename -> | |
433 | string (* extension for marshalled object *) -> | |
434 | (filename list * 'x) -> | |
435 | string (* extension for marshalled dependencies *) -> | |
436 | (unit -> 'a) -> | |
437 | 'a | |
438 | ||
439 | ||
440 | ||
441 | val once : ('a -> unit) -> ('a -> unit) | |
442 | ||
443 | val before_leaving : ('a -> unit) -> 'a -> 'a | |
444 | ||
445 | (* do some finalize, signal handling, unix exit conversion, etc *) | |
446 | val main_boilerplate : (unit -> unit) -> unit | |
447 | ||
448 | ||
449 | (* cf also the timeout function below that are control related too *) | |
450 | ||
451 | ||
452 | (*****************************************************************************) | |
453 | (* Concurrency *) | |
454 | (*****************************************************************************) | |
455 | ||
456 | (* how ensure really atomic file creation ? hehe :) *) | |
457 | exception FileAlreadyLocked | |
458 | val acquire_file_lock : filename -> unit | |
459 | val release_file_lock : filename -> unit | |
460 | ||
461 | (*****************************************************************************) | |
462 | (* Error managment *) | |
463 | (*****************************************************************************) | |
464 | exception Todo | |
465 | exception Impossible | |
466 | exception Here | |
467 | exception ReturnExn | |
468 | ||
0708f913 | 469 | exception Multi_found |
91eba41f | 470 | |
34e49164 C |
471 | exception WrongFormat of string |
472 | ||
473 | ||
474 | val internal_error : string -> 'a | |
475 | val myassert : bool -> unit | |
476 | val warning : string -> 'a -> 'a | |
477 | val error_cant_have : 'a -> 'b | |
478 | ||
479 | val exn_to_s : exn -> string | |
91eba41f C |
480 | (* alias *) |
481 | val string_of_exn : exn -> string | |
34e49164 | 482 | |
b1b2de81 C |
483 | type error = Error of string |
484 | ||
485 | type evotype = unit | |
486 | val evoval : evotype | |
487 | ||
34e49164 C |
488 | (*****************************************************************************) |
489 | (* Environment *) | |
490 | (*****************************************************************************) | |
491 | ||
492 | val check_stack_size: int -> unit | |
493 | val check_stack_nbfiles: int -> unit | |
494 | ||
495 | (* internally common.ml set Gc. parameters *) | |
496 | val _init_gc_stack : unit | |
497 | ||
498 | (*****************************************************************************) | |
499 | (* Arguments and command line *) | |
500 | (*****************************************************************************) | |
501 | ||
502 | type arg_spec_full = Arg.key * Arg.spec * Arg.doc | |
503 | type cmdline_options = arg_spec_full list | |
504 | ||
505 | ||
506 | type options_with_title = string * string * arg_spec_full list | |
507 | type cmdline_sections = options_with_title list | |
508 | ||
509 | ||
510 | (* A wrapper around Arg modules that have more logical argument order, | |
511 | * and returns the remaining args. | |
512 | *) | |
513 | val parse_options : | |
514 | cmdline_options -> Arg.usage_msg -> string array -> string list | |
515 | ||
516 | (* Another wrapper that does Arg.align automatically *) | |
517 | val usage : Arg.usage_msg -> cmdline_options -> unit | |
518 | ||
519 | ||
520 | ||
521 | (* Work with the options_with_title type way to organize a long | |
522 | * list of command line switches. | |
523 | *) | |
524 | val short_usage : | |
525 | Arg.usage_msg -> short_opt:cmdline_options -> unit | |
526 | val long_usage : | |
527 | Arg.usage_msg -> short_opt:cmdline_options -> long_opt:cmdline_sections -> | |
528 | unit | |
529 | ||
530 | (* With the options_with_title way, we don't want the default -help and --help | |
531 | * so need adapter of Arg module, not just wrapper. | |
532 | *) | |
533 | val arg_align2 : cmdline_options -> cmdline_options | |
534 | val arg_parse2 : | |
535 | cmdline_options -> Arg.usage_msg -> (unit -> unit) (* short_usage func *) -> | |
536 | string list | |
537 | ||
538 | ||
539 | ||
540 | ||
541 | ||
542 | (* The action lib. Useful to debug supart of your system. cf some of | |
543 | * my main.ml for example of use. *) | |
544 | type flag_spec = Arg.key * Arg.spec * Arg.doc | |
545 | type action_spec = Arg.key * Arg.doc * action_func | |
546 | and action_func = (string list -> unit) | |
547 | ||
548 | type cmdline_actions = action_spec list | |
549 | exception WrongNumberOfArguments | |
550 | ||
551 | val mk_action_0_arg : (unit -> unit) -> action_func | |
552 | val mk_action_1_arg : (string -> unit) -> action_func | |
553 | val mk_action_2_arg : (string -> string -> unit) -> action_func | |
554 | val mk_action_3_arg : (string -> string -> string -> unit) -> action_func | |
555 | ||
556 | val mk_action_n_arg : (string list -> unit) -> action_func | |
557 | ||
558 | val options_of_actions: | |
559 | string ref (* the action ref *) -> cmdline_actions -> cmdline_options | |
560 | val action_list: | |
561 | cmdline_actions -> Arg.key list | |
562 | val do_action: | |
563 | Arg.key -> string list (* args *) -> cmdline_actions -> unit | |
564 | ||
565 | (*****************************************************************************) | |
566 | (* Equality *) | |
567 | (*****************************************************************************) | |
568 | ||
569 | (* Using the generic (=) is tempting, but it backfires, so better avoid it *) | |
570 | ||
571 | (* To infer all the code that use an equal, and that should be | |
572 | * transformed, is not that easy, because (=) is used by many | |
573 | * functions, such as List.find, List.mem, and so on. The strategy to find | |
574 | * them is to turn what you were previously using into a function, because | |
575 | * (=) return an exception when applied to a function, then you simply | |
576 | * use ocamldebug to detect where the code has to be transformed by | |
577 | * finding where the exception was launched from. | |
578 | *) | |
579 | ||
580 | val (=|=) : int -> int -> bool | |
581 | val (=<=) : char -> char -> bool | |
582 | val (=$=) : string -> string -> bool | |
583 | val (=:=) : bool -> bool -> bool | |
584 | ||
585 | val (=*=): 'a -> 'a -> bool | |
586 | ||
587 | (* if want to restrict the use of '=', uncomment this: | |
588 | * | |
b1b2de81 | 589 | * val (=): unit -> unit -> bool |
34e49164 C |
590 | * |
591 | * But it will not forbid you to use caml functions like List.find, List.mem | |
592 | * which internaly use this convenient but evolution-unfriendly (=) | |
593 | *) | |
594 | ||
595 | ||
596 | ||
34e49164 C |
597 | (*###########################################################################*) |
598 | (* And now basic types *) | |
599 | (*###########################################################################*) | |
600 | ||
601 | (*****************************************************************************) | |
602 | (* Bool *) | |
603 | (*****************************************************************************) | |
604 | ||
605 | val ( ||| ) : 'a -> 'a -> 'a | |
606 | val ( ==> ) : bool -> bool -> bool | |
607 | val xor : 'a -> 'a -> bool | |
608 | ||
609 | ||
0708f913 | 610 | |
34e49164 C |
611 | (*****************************************************************************) |
612 | (* Char *) | |
613 | (*****************************************************************************) | |
614 | ||
615 | val string_of_char : char -> string | |
616 | val string_of_chars : char list -> string | |
617 | ||
618 | val is_single : char -> bool | |
619 | val is_symbol : char -> bool | |
620 | val is_space : char -> bool | |
621 | val is_upper : char -> bool | |
622 | val is_lower : char -> bool | |
623 | val is_alpha : char -> bool | |
624 | val is_digit : char -> bool | |
625 | ||
626 | val cbetween : char -> char -> char -> bool | |
627 | ||
628 | (*****************************************************************************) | |
629 | (* Num *) | |
630 | (*****************************************************************************) | |
631 | ||
632 | val ( /! ) : int -> int -> int | |
633 | ||
634 | val do_n : int -> (unit -> unit) -> unit | |
635 | val foldn : ('a -> int -> 'a) -> 'a -> int -> 'a | |
636 | ||
34e49164 C |
637 | val pi : float |
638 | val pi2 : float | |
639 | val pi4 : float | |
640 | ||
641 | val deg_to_rad : float -> float | |
642 | ||
643 | val clampf : float -> float | |
644 | ||
645 | val square : float -> float | |
646 | val power : int -> int -> int | |
647 | ||
648 | val between : 'a -> 'a -> 'a -> bool | |
649 | val between_strict : int -> int -> int -> bool | |
650 | val bitrange : int -> int -> bool | |
651 | ||
652 | val prime1 : int -> int option | |
653 | val prime : int -> int option | |
654 | ||
655 | val sum : int list -> int | |
656 | val product : int list -> int | |
657 | ||
658 | val decompose : int -> int list | |
659 | ||
660 | val mysquare : int -> int | |
661 | val sqr : float -> float | |
662 | ||
663 | type compare = Equal | Inf | Sup | |
664 | val ( <=> ) : 'a -> 'a -> compare | |
665 | val ( <==> ) : 'a -> 'a -> int | |
666 | ||
667 | type uint = int | |
668 | ||
669 | val int_of_stringchar : string -> int | |
670 | val int_of_base : string -> int -> int | |
671 | val int_of_stringbits : string -> int | |
672 | val int_of_octal : string -> int | |
673 | val int_of_all : string -> int | |
674 | ||
675 | (* useful but sometimes when want grep for all places where do modif, | |
676 | * easier to have just code using ':=' and '<-' to do some modifications. | |
677 | * In the same way avoid using {contents = xxx} to build some ref. | |
678 | *) | |
679 | val ( += ) : int ref -> int -> unit | |
680 | val ( -= ) : int ref -> int -> unit | |
681 | ||
682 | val pourcent: int -> int -> int | |
683 | val pourcent_float: int -> int -> float | |
684 | val pourcent_float_of_floats: float -> float -> float | |
685 | ||
91eba41f C |
686 | val pourcent_good_bad: int -> int -> int |
687 | val pourcent_good_bad_float: int -> int -> float | |
688 | ||
689 | type 'a max_with_elem = int ref * 'a ref | |
690 | val update_max_with_elem: | |
691 | 'a max_with_elem -> is_better:(int -> int ref -> bool) -> int * 'a -> unit | |
34e49164 C |
692 | (*****************************************************************************) |
693 | (* Numeric/overloading *) | |
694 | (*****************************************************************************) | |
695 | ||
696 | type 'a numdict = | |
697 | NumDict of | |
698 | (('a -> 'a -> 'a) * ('a -> 'a -> 'a) * ('a -> 'a -> 'a) * ('a -> 'a)) | |
699 | val add : 'a numdict -> 'a -> 'a -> 'a | |
700 | val mul : 'a numdict -> 'a -> 'a -> 'a | |
701 | val div : 'a numdict -> 'a -> 'a -> 'a | |
702 | val neg : 'a numdict -> 'a -> 'a | |
703 | ||
704 | val numd_int : int numdict | |
705 | val numd_float : float numdict | |
706 | ||
707 | val testd : 'a numdict -> 'a -> 'a | |
708 | ||
709 | ||
710 | module ArithFloatInfix : sig | |
711 | val (+) : float -> float -> float | |
712 | val (-) : float -> float -> float | |
713 | val (/) : float -> float -> float | |
714 | val ( * ) : float -> float -> float | |
715 | ||
716 | ||
717 | val (+..) : int -> int -> int | |
718 | val (-..) : int -> int -> int | |
719 | val (/..) : int -> int -> int | |
720 | val ( *..) : int -> int -> int | |
721 | ||
722 | val (+=) : float ref -> float -> unit | |
723 | end | |
724 | ||
725 | (*****************************************************************************) | |
726 | (* Random *) | |
727 | (*****************************************************************************) | |
728 | ||
729 | val _init_random : unit | |
730 | val random_list : 'a list -> 'a | |
731 | val randomize_list : 'a list -> 'a list | |
732 | val random_subset_of_list : int -> 'a list -> 'a list | |
733 | ||
734 | ||
735 | (*****************************************************************************) | |
736 | (* Tuples *) | |
737 | (*****************************************************************************) | |
738 | ||
739 | type 'a pair = 'a * 'a | |
740 | type 'a triple = 'a * 'a * 'a | |
741 | ||
742 | val fst3 : 'a * 'b * 'c -> 'a | |
743 | val snd3 : 'a * 'b * 'c -> 'b | |
744 | val thd3 : 'a * 'b * 'c -> 'c | |
745 | ||
746 | val sndthd : 'a * 'b * 'c -> 'b * 'c | |
747 | ||
748 | val map_fst : ('a -> 'b) -> 'a * 'c -> 'b * 'c | |
749 | val map_snd : ('a -> 'b) -> 'c * 'a -> 'c * 'b | |
750 | ||
751 | val pair : ('a -> 'b) -> 'a * 'a -> 'b * 'b | |
752 | ||
753 | val snd : 'a * 'b -> 'b (* alias *) | |
754 | val fst : 'a * 'b -> 'a (* alias *) | |
755 | ||
756 | val double : 'a -> 'a * 'a | |
757 | val swap : 'a * 'b -> 'b * 'a | |
758 | ||
759 | (* maybe a sign of bad programming if use those functions :) *) | |
760 | val tuple_of_list1 : 'a list -> 'a | |
761 | val tuple_of_list2 : 'a list -> 'a * 'a | |
762 | val tuple_of_list3 : 'a list -> 'a * 'a * 'a | |
763 | val tuple_of_list4 : 'a list -> 'a * 'a * 'a * 'a | |
764 | val tuple_of_list5 : 'a list -> 'a * 'a * 'a * 'a * 'a | |
765 | val tuple_of_list6 : 'a list -> 'a * 'a * 'a * 'a * 'a * 'a | |
766 | ||
767 | (*****************************************************************************) | |
768 | (* Maybe *) | |
769 | (*****************************************************************************) | |
770 | ||
771 | type ('a, 'b) either = Left of 'a | Right of 'b | |
772 | type ('a, 'b, 'c) either3 = Left3 of 'a | Middle3 of 'b | Right3 of 'c | |
773 | ||
774 | val just : 'a option -> 'a | |
775 | val some : 'a option -> 'a (* alias *) | |
776 | ||
777 | val fmap : ('a -> 'b) -> 'a option -> 'b option | |
778 | val map_option : ('a -> 'b) -> 'a option -> 'b option (* alias *) | |
779 | ||
780 | val do_option : ('a -> unit) -> 'a option -> unit | |
781 | ||
782 | val optionise : (unit -> 'a) -> 'a option | |
783 | ||
784 | val some_or : 'a option -> 'a -> 'a | |
785 | ||
786 | val partition_either : | |
787 | ('a -> ('b, 'c) either) -> 'a list -> 'b list * 'c list | |
788 | ||
789 | val filter_some : 'a option list -> 'a list | |
790 | val map_filter : ('a -> 'b option) -> 'a list -> 'b list | |
791 | val find_some : ('a -> 'b option) -> 'a list -> 'b | |
792 | ||
0708f913 C |
793 | val list_to_single_or_exn: 'a list -> 'a |
794 | ||
795 | (*****************************************************************************) | |
796 | (* TriBool *) | |
797 | (*****************************************************************************) | |
798 | type bool3 = True3 | False3 | TrueFalsePb3 of string | |
799 | ||
800 | ||
34e49164 C |
801 | (*****************************************************************************) |
802 | (* Strings *) | |
803 | (*****************************************************************************) | |
804 | ||
805 | val slength : string -> int (* alias *) | |
806 | val concat : string -> string list -> string (* alias *) | |
807 | ||
808 | val i_to_s : int -> string | |
809 | val s_to_i : string -> int | |
810 | ||
811 | (* strings take space in memory. Better when can share the space used by | |
812 | * similar strings. | |
813 | *) | |
814 | val _shareds : (string, string) Hashtbl.t | |
815 | val shared_string : string -> string | |
816 | ||
817 | val chop : string -> string | |
818 | val chop_dirsymbol : string -> string | |
819 | ||
820 | val ( <!!> ) : string -> int * int -> string | |
821 | val ( <!> ) : string -> int -> char | |
822 | ||
91eba41f C |
823 | val take_string: int -> string -> string |
824 | val take_string_safe: int -> string -> string | |
825 | ||
34e49164 C |
826 | val split_on_char : char -> string -> string list |
827 | ||
828 | val lowercase : string -> string | |
829 | ||
830 | val quote : string -> string | |
831 | ||
832 | val null_string : string -> bool | |
833 | val is_blank_string : string -> bool | |
834 | val is_string_prefix : string -> string -> bool | |
835 | ||
836 | ||
837 | val plural : int -> string -> string | |
838 | ||
839 | val showCodeHex : int list -> unit | |
840 | ||
841 | val size_mo_ko : int -> string | |
842 | val size_ko : int -> string | |
843 | ||
844 | val edit_distance: string -> string -> int | |
845 | ||
485bce71 C |
846 | val md5sum_of_string : string -> string |
847 | ||
34e49164 C |
848 | (*****************************************************************************) |
849 | (* Regexp *) | |
850 | (*****************************************************************************) | |
851 | ||
852 | val regexp_alpha : Str.regexp | |
485bce71 | 853 | val regexp_word : Str.regexp |
34e49164 C |
854 | |
855 | val _memo_compiled_regexp : (string, Str.regexp) Hashtbl.t | |
856 | val ( =~ ) : string -> string -> bool | |
857 | val ( ==~ ) : string -> Str.regexp -> bool | |
858 | ||
859 | ||
860 | ||
861 | val regexp_match : string -> string -> string | |
862 | ||
863 | val matched : int -> string -> string | |
864 | ||
865 | (* not yet politypic functions in ocaml *) | |
866 | val matched1 : string -> string | |
867 | val matched2 : string -> string * string | |
868 | val matched3 : string -> string * string * string | |
869 | val matched4 : string -> string * string * string * string | |
870 | val matched5 : string -> string * string * string * string * string | |
871 | val matched6 : string -> string * string * string * string * string * string | |
872 | val matched7 : string -> string * string * string * string * string * string * string | |
873 | ||
874 | val string_match_substring : Str.regexp -> string -> bool | |
875 | ||
876 | val split : string (* sep regexp *) -> string -> string list | |
877 | val join : string (* sep *) -> string list -> string | |
878 | ||
879 | val split_list_regexp : string -> string list -> (string * string list) list | |
880 | ||
881 | val all_match : string (* regexp *) -> string -> string list | |
485bce71 C |
882 | val global_replace_regexp : |
883 | string (* regexp *) -> (string -> string) -> string -> string | |
884 | ||
885 | val regular_words: string -> string list | |
886 | val contain_regular_word: string -> bool | |
34e49164 C |
887 | |
888 | (*****************************************************************************) | |
889 | (* Filenames *) | |
890 | (*****************************************************************************) | |
891 | ||
892 | (* now at beginning of this file: type filename = string *) | |
893 | val dirname : string -> string | |
894 | val basename : string -> string | |
895 | ||
896 | val filesuffix : filename -> string | |
897 | val fileprefix : filename -> string | |
898 | ||
899 | val adjust_ext_if_needed : filename -> string -> filename | |
900 | ||
901 | (* db for dir, base *) | |
902 | val db_of_filename : filename -> (string * filename) | |
903 | val filename_of_db : (string * filename) -> filename | |
904 | ||
905 | (* dbe for dir, base, ext *) | |
906 | val dbe_of_filename : filename -> string * string * string | |
907 | val dbe_of_filename_nodot : filename -> string * string * string | |
908 | (* Left (d,b,e) | Right (d,b) if file has no extension *) | |
909 | val dbe_of_filename_safe : | |
910 | filename -> (string * string * string, string * string) either | |
911 | ||
912 | val filename_of_dbe : string * string * string -> filename | |
913 | ||
914 | (* ex: replace_ext "toto.c" "c" "var" *) | |
915 | val replace_ext: filename -> string -> string -> filename | |
916 | ||
917 | (* remove the ., .. *) | |
918 | val normalize_path : filename -> filename | |
919 | ||
920 | val relative_to_absolute : filename -> filename | |
921 | ||
91eba41f C |
922 | val is_relative: filename -> bool |
923 | val is_absolute: filename -> bool | |
924 | ||
34e49164 C |
925 | val filename_without_leading_path : string -> filename -> filename |
926 | ||
927 | (*****************************************************************************) | |
928 | (* i18n *) | |
929 | (*****************************************************************************) | |
930 | type langage = | |
931 | | English | |
932 | | Francais | |
933 | | Deutsch | |
934 | ||
935 | (*****************************************************************************) | |
936 | (* Dates *) | |
937 | (*****************************************************************************) | |
938 | ||
939 | (* can also use ocamlcalendar, but heavier, use many modules ... *) | |
940 | ||
941 | type month = | |
942 | | Jan | Feb | Mar | Apr | May | Jun | |
943 | | Jul | Aug | Sep | Oct | Nov | Dec | |
944 | type year = Year of int | |
945 | type day = Day of int | |
946 | ||
947 | type date_dmy = DMY of day * month * year | |
948 | ||
949 | type hour = Hour of int | |
950 | type minute = Min of int | |
951 | type second = Sec of int | |
952 | ||
953 | type time_hms = HMS of hour * minute * second | |
954 | ||
955 | type full_date = date_dmy * time_hms | |
956 | ||
957 | ||
958 | (* intervalle *) | |
959 | type days = Days of int | |
960 | ||
961 | type time_dmy = TimeDMY of day * month * year | |
962 | ||
963 | ||
964 | (* from Unix *) | |
965 | type float_time = float | |
966 | ||
967 | ||
968 | val mk_date_dmy : int -> int -> int -> date_dmy | |
969 | ||
970 | ||
971 | val check_date_dmy : date_dmy -> unit | |
972 | val check_time_dmy : time_dmy -> unit | |
973 | val check_time_hms : time_hms -> unit | |
974 | ||
975 | val int_to_month : int -> string | |
976 | val int_of_month : month -> int | |
977 | val month_of_string : string -> month | |
978 | val month_of_string_long : string -> month | |
979 | val string_of_month : month -> string | |
980 | ||
981 | val string_of_date_dmy : date_dmy -> string | |
982 | val string_of_unix_time : ?langage:langage -> Unix.tm -> string | |
983 | val short_string_of_unix_time : ?langage:langage -> Unix.tm -> string | |
984 | val string_of_floattime: ?langage:langage -> float_time -> string | |
985 | val short_string_of_floattime: ?langage:langage -> float_time -> string | |
986 | ||
987 | val floattime_of_string: string -> float_time | |
988 | ||
989 | val dmy_to_unixtime: date_dmy -> float_time * Unix.tm | |
990 | val unixtime_to_dmy: Unix.tm -> date_dmy | |
991 | val unixtime_to_floattime: Unix.tm -> float_time | |
0708f913 | 992 | val floattime_to_unixtime: float_time -> Unix.tm |
34e49164 C |
993 | |
994 | val sec_to_days : int -> string | |
995 | val sec_to_hours : int -> string | |
996 | ||
997 | val today : unit -> float_time | |
998 | val yesterday : unit -> float_time | |
999 | val tomorrow : unit -> float_time | |
1000 | ||
1001 | val lastweek : unit -> float_time | |
1002 | val lastmonth : unit -> float_time | |
1003 | ||
1004 | val week_before: float_time -> float_time | |
1005 | val month_before: float_time -> float_time | |
1006 | val week_after: float_time -> float_time | |
1007 | ||
1008 | val days_in_week_of_day : float_time -> float_time list | |
1009 | ||
1010 | val first_day_in_week_of_day : float_time -> float_time | |
1011 | val last_day_in_week_of_day : float_time -> float_time | |
1012 | ||
1013 | val day_secs: float_time | |
1014 | ||
1015 | val rough_days_since_jesus : date_dmy -> days | |
1016 | val rough_days_between_dates : date_dmy -> date_dmy -> days | |
1017 | ||
1018 | val string_of_unix_time_lfs : Unix.tm -> string | |
1019 | ||
485bce71 C |
1020 | val is_more_recent : date_dmy -> date_dmy -> bool |
1021 | val max_dmy : date_dmy -> date_dmy -> date_dmy | |
1022 | val min_dmy : date_dmy -> date_dmy -> date_dmy | |
1023 | val maximum_dmy : date_dmy list -> date_dmy | |
1024 | val minimum_dmy : date_dmy list -> date_dmy | |
34e49164 C |
1025 | |
1026 | (*****************************************************************************) | |
1027 | (* Lines/Words/Strings *) | |
1028 | (*****************************************************************************) | |
1029 | ||
1030 | val list_of_string : string -> char list | |
1031 | ||
1032 | val lines : string -> string list | |
1033 | val unlines : string list -> string | |
1034 | ||
1035 | val words : string -> string list | |
1036 | val unwords : string list -> string | |
1037 | ||
1038 | val split_space : string -> string list | |
1039 | ||
1040 | val lines_with_nl : string -> string list | |
1041 | ||
1042 | val nblines : string -> int | |
1043 | ||
1044 | (*****************************************************************************) | |
1045 | (* Process/Files *) | |
1046 | (*****************************************************************************) | |
1047 | val cat : filename -> string list | |
1048 | val cat_orig : filename -> string list | |
91eba41f C |
1049 | val cat_array: filename -> string array |
1050 | ||
1051 | val uncat: string list -> filename -> unit | |
34e49164 C |
1052 | |
1053 | val interpolate : string -> string list | |
1054 | ||
1055 | val echo : string -> string | |
1056 | ||
1057 | val usleep : int -> unit | |
1058 | ||
1059 | val process_output_to_list : string -> string list | |
1060 | val cmd_to_list : string -> string list (* alias *) | |
1061 | val cmd_to_list_and_status : string -> string list * Unix.process_status | |
1062 | ||
1063 | val command2 : string -> unit | |
91eba41f | 1064 | val _batch_mode: bool ref |
34e49164 | 1065 | val command2_y_or_no : string -> bool |
0708f913 | 1066 | val command2_y_or_no_exit_if_no : string -> unit |
34e49164 C |
1067 | |
1068 | val do_in_fork : (unit -> unit) -> int | |
1069 | ||
1070 | val mkdir: ?mode:Unix.file_perm -> string -> unit | |
1071 | ||
1072 | val read_file : filename -> string | |
1073 | val write_file : file:filename -> string -> unit | |
1074 | ||
1075 | val filesize : filename -> int | |
1076 | val filemtime : filename -> float | |
1077 | ||
1078 | val nblines_file : filename -> int | |
1079 | ||
1080 | val lfile_exists : filename -> bool | |
1081 | val is_directory : filename -> bool | |
1082 | ||
1083 | val capsule_unix : ('a -> unit) -> 'a -> unit | |
1084 | ||
1085 | val readdir_to_kind_list : string -> Unix.file_kind -> string list | |
1086 | val readdir_to_dir_list : string -> string list | |
1087 | val readdir_to_file_list : string -> string list | |
1088 | val readdir_to_link_list : string -> string list | |
1089 | val readdir_to_dir_size_list : string -> (string * int) list | |
1090 | ||
1091 | val glob : string -> filename list | |
1092 | val files_of_dir_or_files : | |
1093 | string (* ext *) -> string list -> filename list | |
1094 | val files_of_dir_or_files_no_vcs : | |
1095 | string (* ext *) -> string list -> filename list | |
1096 | (* use a post filter =~ for the ext filtering *) | |
1097 | val files_of_dir_or_files_no_vcs_post_filter : | |
1098 | string (* regexp *) -> string list -> filename list | |
1099 | ||
1100 | ||
1101 | val sanity_check_files_and_adjust : | |
1102 | string (* ext *) -> string list -> filename list | |
1103 | ||
1104 | ||
1105 | type rwx = [ `R | `W | `X ] list | |
1106 | val file_perm_of : u:rwx -> g:rwx -> o:rwx -> Unix.file_perm | |
1107 | ||
1108 | val has_env : string -> bool | |
1109 | ||
1110 | (* scheme spirit. do a finalize so no leak. *) | |
1111 | val with_open_outfile : | |
1112 | filename -> ((string -> unit) * out_channel -> 'a) -> 'a | |
1113 | val with_open_infile : | |
1114 | filename -> (in_channel -> 'a) -> 'a | |
1115 | val with_open_outfile_append : | |
1116 | filename -> ((string -> unit) * out_channel -> 'a) -> 'a | |
1117 | ||
1118 | val with_open_stringbuf : | |
1119 | (((string -> unit) * Buffer.t) -> unit) -> string | |
1120 | ||
1121 | exception Timeout | |
1122 | ||
1123 | (* subtil: have to make sure that Timeout is not intercepted before here. So | |
1124 | * avoid exn handler such as try (...) with _ -> cos Timeout will not bubble up | |
1125 | * enough. In such case, add a case before such as | |
1126 | * with Timeout -> raise Timeout | _ -> ... | |
1127 | * | |
1128 | * The same is true for UnixExit (see below). | |
1129 | *) | |
1130 | val timeout_function : int -> (unit -> 'a) -> 'a | |
1131 | ||
1132 | val timeout_function_opt : int option -> (unit -> 'a) -> 'a | |
1133 | ||
1134 | ||
1135 | (* creation of /tmp files, a la gcc | |
1136 | * ex: new_temp_file "cocci" ".c" will give "/tmp/cocci-3252-434465.c" | |
1137 | *) | |
1138 | val _temp_files_created : string list ref | |
1139 | (* see flag: val save_tmp_files : bool ref *) | |
1140 | val new_temp_file : string (* prefix *) -> string (* suffix *) -> filename | |
1141 | val erase_temp_files : unit -> unit | |
1142 | ||
1143 | (* If the user use some exit 0 in his code, then no one can intercept this | |
1144 | * exit and do something before exiting. There is exn handler for exit 0 | |
1145 | * so better never use exit 0 but instead use an exception and just at | |
1146 | * the very toplevel transform this exn in a unix exit code. | |
1147 | * | |
1148 | * subtil: same problem than with Timeout. Do not intercept such exception | |
1149 | * with some blind try (...) with _ -> ... | |
1150 | *) | |
1151 | exception UnixExit of int | |
1152 | val exn_to_real_unixexit : (unit -> 'a) -> 'a | |
1153 | ||
1154 | ||
1155 | ||
1156 | ||
1157 | ||
1158 | ||
1159 | ||
1160 | ||
1161 | (*###########################################################################*) | |
1162 | (* And now collection-like types. See also ocollection.mli *) | |
1163 | (*###########################################################################*) | |
1164 | ||
1165 | (*****************************************************************************) | |
1166 | (* List *) | |
1167 | (*****************************************************************************) | |
1168 | ||
485bce71 | 1169 | |
34e49164 C |
1170 | (* tail recursive efficient map (but that also reverse the element!) *) |
1171 | val map_eff_rev : ('a -> 'b) -> 'a list -> 'b list | |
1172 | (* tail recursive efficient map, use accumulator *) | |
1173 | val acc_map : ('a -> 'b) -> 'a list -> 'b list | |
1174 | ||
1175 | ||
1176 | val zip : 'a list -> 'b list -> ('a * 'b) list | |
1177 | val zip_safe : 'a list -> 'b list -> ('a * 'b) list | |
1178 | val unzip : ('a * 'b) list -> 'a list * 'b list | |
1179 | ||
1180 | val take : int -> 'a list -> 'a list | |
1181 | val take_safe : int -> 'a list -> 'a list | |
1182 | val take_until : ('a -> bool) -> 'a list -> 'a list | |
1183 | val take_while : ('a -> bool) -> 'a list -> 'a list | |
1184 | ||
1185 | val drop : int -> 'a list -> 'a list | |
1186 | val drop_while : ('a -> bool) -> 'a list -> 'a list | |
1187 | val drop_until : ('a -> bool) -> 'a list -> 'a list | |
1188 | ||
1189 | val span : ('a -> bool) -> 'a list -> 'a list * 'a list | |
1190 | ||
1191 | val skip_until : ('a list -> bool) -> 'a list -> 'a list | |
b1b2de81 | 1192 | val skipfirst : (* Eq a *) 'a -> 'a list -> 'a list |
34e49164 C |
1193 | |
1194 | (* cf also List.partition *) | |
1195 | val fpartition : ('a -> 'b option) -> 'a list -> 'b list * 'a list | |
1196 | ||
1197 | val groupBy : ('a -> 'a -> bool) -> 'a list -> 'a list list | |
1198 | val exclude_but_keep_attached: ('a -> bool) -> 'a list -> ('a * 'a list) list | |
b1b2de81 C |
1199 | val group_by_post: ('a -> bool) -> 'a list -> ('a list * 'a) list * 'a list |
1200 | val group_by_pre: ('a -> bool) -> 'a list -> 'a list * ('a * 'a list) list | |
0708f913 | 1201 | val group_by_mapped_key: ('a -> 'b) -> 'a list -> ('b * 'a list) list |
34e49164 | 1202 | |
91eba41f C |
1203 | (* Use hash internally to not be in O(n2). If you want to use it on a |
1204 | * simple list, then first do a List.map to generate a key, for instance the | |
1205 | * first char of the element, and then use this function. | |
1206 | *) | |
34e49164 C |
1207 | val group_assoc_bykey_eff : ('a * 'b) list -> ('a * 'b list) list |
1208 | ||
1209 | val splitAt : int -> 'a list -> 'a list * 'a list | |
1210 | ||
1211 | val split_when: ('a -> bool) -> 'a list -> 'a list * 'a * 'a list | |
1212 | val split_gen_when: ('a list -> 'a list option) -> 'a list -> 'a list list | |
1213 | ||
1214 | val pack : int -> 'a list -> 'a list list | |
1215 | ||
1216 | ||
1217 | val enum : int -> int -> int list | |
1218 | val repeat : 'a -> int -> 'a list | |
1219 | val generate : int -> 'a -> 'a list | |
1220 | ||
1221 | ||
1222 | ||
1223 | val index_list : 'a list -> ('a * int) list | |
1224 | val index_list_1 : 'a list -> ('a * int) list | |
1225 | val index_list_and_total : 'a list -> ('a * int * int) list | |
1226 | ||
1227 | val iter_index : ('a -> int -> 'b) -> 'a list -> unit | |
1228 | val map_index : ('a -> int -> 'b) -> 'a list -> 'b list | |
1229 | val filter_index : (int -> 'a -> bool) -> 'a list -> 'a list | |
1230 | val fold_left_with_index : ('a -> 'b -> int -> 'a) -> 'a -> 'b list -> 'a | |
1231 | ||
1232 | val nth : 'a list -> int -> 'a | |
b1b2de81 | 1233 | val rang : (* Eq a *) 'a -> 'a list -> int |
34e49164 C |
1234 | |
1235 | val last_n : int -> 'a list -> 'a list | |
1236 | ||
1237 | ||
1238 | ||
1239 | val snoc : 'a -> 'a list -> 'a list | |
1240 | val cons : 'a -> 'a list -> 'a list | |
1241 | val uncons : 'a list -> 'a * 'a list | |
1242 | val safe_tl : 'a list -> 'a list | |
1243 | val head_middle_tail : 'a list -> 'a * 'a list * 'a | |
1244 | val last : 'a list -> 'a | |
1245 | val list_init : 'a list -> 'a list | |
1246 | val list_last : 'a list -> 'a | |
1247 | val removelast : 'a list -> 'a list | |
1248 | ||
1249 | val inits : 'a list -> 'a list list | |
1250 | val tails : 'a list -> 'a list list | |
1251 | ||
1252 | ||
1253 | val ( ++ ) : 'a list -> 'a list -> 'a list | |
1254 | ||
1255 | val foldl1 : ('a -> 'a -> 'a) -> 'a list -> 'a | |
1256 | val fold_k : ('a -> 'b -> ('a -> 'a) -> 'a) -> ('a -> 'a) -> 'a -> 'b list -> 'a | |
1257 | val fold_right1 : ('a -> 'a -> 'a) -> 'a list -> 'a | |
1258 | val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a | |
1259 | ||
1260 | val rev_map : ('a -> 'b) -> 'a list -> 'b list | |
1261 | ||
1262 | val join_gen : 'a -> 'a list -> 'a list | |
1263 | ||
1264 | val do_withenv : | |
1265 | (('a -> 'b) -> 'c -> 'd) -> ('e -> 'a -> 'b * 'e) -> 'e -> 'c -> 'd * 'e | |
1266 | val map_withenv : ('a -> 'b -> 'c * 'a) -> 'a -> 'b list -> 'c list * 'a | |
113803cf | 1267 | val map_withkeep: ('a -> 'b) -> 'a list -> ('b * 'a) list |
34e49164 C |
1268 | |
1269 | val collect_accu : ('a -> 'b list) -> 'b list -> 'a list -> 'b list | |
1270 | val collect : ('a -> 'b list) -> 'a list -> 'b list | |
1271 | ||
1272 | val remove : 'a -> 'a list -> 'a list | |
1273 | ||
1274 | val exclude : ('a -> bool) -> 'a list -> 'a list | |
1275 | ||
1276 | (* Not like unix uniq command line tool that only delete contiguous repeated | |
1277 | * line. Here we delete any repeated line (here list element). | |
1278 | *) | |
1279 | val uniq : 'a list -> 'a list | |
91eba41f C |
1280 | val uniq_eff: 'a list -> 'a list |
1281 | ||
113803cf C |
1282 | val has_no_duplicate: 'a list -> bool |
1283 | val is_set_as_list: 'a list -> bool | |
1284 | val get_duplicates: 'a list -> 'a list | |
1285 | ||
34e49164 C |
1286 | val doublon : 'a list -> bool |
1287 | ||
1288 | val reverse : 'a list -> 'a list (* alias *) | |
1289 | val rev : 'a list -> 'a list (* alias *) | |
1290 | val rotate : 'a list -> 'a list | |
1291 | ||
1292 | val map_flatten : ('a -> 'b list) -> 'a list -> 'b list | |
1293 | ||
1294 | val map2 : ('a -> 'b) -> 'a list -> 'b list | |
1295 | val map3 : ('a -> 'b) -> 'a list -> 'b list | |
1296 | ||
1297 | ||
1298 | val maximum : 'a list -> 'a | |
1299 | val minimum : 'a list -> 'a | |
1300 | ||
1301 | val min_with : ('a -> 'b) -> 'a list -> 'a | |
1302 | val two_mins_with : ('a -> 'b) -> 'a list -> 'a * 'a | |
1303 | ||
b1b2de81 | 1304 | val all_assoc : (* Eq a *) 'a -> ('a * 'b) list -> 'b list |
34e49164 C |
1305 | val prepare_want_all_assoc : ('a * 'b) list -> ('a * 'b list) list |
1306 | ||
1307 | val or_list : bool list -> bool | |
1308 | val and_list : bool list -> bool | |
1309 | ||
485bce71 C |
1310 | val sum_float : float list -> float |
1311 | val sum_int : int list -> int | |
1312 | val avg_list: int list -> float | |
1313 | ||
34e49164 C |
1314 | val return_when : ('a -> 'b option) -> 'a list -> 'b |
1315 | ||
1316 | ||
1317 | val grep_with_previous : ('a -> 'a -> bool) -> 'a list -> 'a list | |
1318 | val iter_with_previous : ('a -> 'a -> 'b) -> 'a list -> unit | |
1319 | ||
1320 | val iter_with_before_after : | |
1321 | ('a list -> 'a -> 'a list -> unit) -> 'a list -> unit | |
1322 | ||
1323 | val get_pair : 'a list -> ('a * 'a) list | |
1324 | ||
1325 | val permutation : 'a list -> 'a list list | |
1326 | ||
1327 | val remove_elem_pos : int -> 'a list -> 'a list | |
1328 | val insert_elem_pos : ('a * int) -> 'a list -> 'a list | |
1329 | val uncons_permut : 'a list -> (('a * int) * 'a list) list | |
1330 | val uncons_permut_lazy : 'a list -> (('a * int) * 'a list Lazy.t) list | |
1331 | ||
1332 | ||
1333 | val pack_sorted : ('a -> 'a -> bool) -> 'a list -> 'a list list | |
1334 | ||
1335 | val keep_best : ('a * 'a -> 'a option) -> 'a list -> 'a list | |
1336 | val sorted_keep_best : ('a -> 'a -> 'a option) -> 'a list -> 'a list | |
1337 | ||
91eba41f | 1338 | |
34e49164 C |
1339 | val cartesian_product : 'a list -> 'b list -> ('a * 'b) list |
1340 | ||
1341 | (* old stuff *) | |
1342 | val surEnsemble : 'a list -> 'a list list -> 'a list list | |
1343 | val realCombinaison : 'a list -> 'a list list | |
1344 | val combinaison : 'a list -> ('a * 'a) list | |
1345 | val insere : 'a -> 'a list list -> 'a list list | |
1346 | val insereListeContenant : 'a list -> 'a -> 'a list list -> 'a list list | |
1347 | val fusionneListeContenant : 'a * 'a -> 'a list list -> 'a list list | |
1348 | ||
1349 | (*****************************************************************************) | |
1350 | (* Arrays *) | |
1351 | (*****************************************************************************) | |
1352 | ||
b1b2de81 C |
1353 | val array_find_index : (int -> bool) -> 'a array -> int |
1354 | val array_find_index_via_elem : ('a -> bool) -> 'a array -> int | |
1355 | ||
1356 | (* for better type checking, as sometimes when have an 'int array', can | |
1357 | * easily mess up the index from the value. | |
1358 | *) | |
1359 | type idx = Idx of int | |
1360 | val next_idx: idx -> idx | |
1361 | val int_of_idx: idx -> int | |
1362 | ||
1363 | val array_find_index_typed : (idx -> bool) -> 'a array -> idx | |
34e49164 | 1364 | |
91eba41f C |
1365 | (*****************************************************************************) |
1366 | (* Matrix *) | |
1367 | (*****************************************************************************) | |
1368 | ||
34e49164 C |
1369 | type 'a matrix = 'a array array |
1370 | ||
1371 | val map_matrix : ('a -> 'b) -> 'a matrix -> 'b matrix | |
1372 | ||
91eba41f C |
1373 | val make_matrix_init: |
1374 | nrow:int -> ncolumn:int -> (int -> int -> 'a) -> 'a matrix | |
1375 | ||
1376 | val iter_matrix: | |
1377 | (int -> int -> 'a -> unit) -> 'a matrix -> unit | |
1378 | ||
1379 | val nb_rows_matrix: 'a matrix -> int | |
1380 | val nb_columns_matrix: 'a matrix -> int | |
1381 | ||
1382 | val rows_of_matrix: 'a matrix -> 'a list list | |
1383 | val columns_of_matrix: 'a matrix -> 'a list list | |
1384 | ||
1385 | val all_elems_matrix_by_row: 'a matrix -> 'a list | |
1386 | ||
34e49164 C |
1387 | (*****************************************************************************) |
1388 | (* Fast array *) | |
1389 | (*****************************************************************************) | |
1390 | ||
1391 | (* ?? *) | |
1392 | ||
1393 | (*****************************************************************************) | |
1394 | (* Set. But have a look too at set*.mli; it's better. Or use Hashtbl. *) | |
1395 | (*****************************************************************************) | |
1396 | ||
1397 | type 'a set = 'a list | |
1398 | ||
1399 | val empty_set : 'a set | |
1400 | ||
1401 | val insert_set : 'a -> 'a set -> 'a set | |
1402 | val single_set : 'a -> 'a set | |
1403 | val set : 'a list -> 'a set | |
1404 | ||
113803cf C |
1405 | val is_set: 'a list -> bool |
1406 | ||
34e49164 C |
1407 | val exists_set : ('a -> bool) -> 'a set -> bool |
1408 | val forall_set : ('a -> bool) -> 'a set -> bool | |
1409 | ||
1410 | val filter_set : ('a -> bool) -> 'a set -> 'a set | |
1411 | val fold_set : ('a -> 'b -> 'a) -> 'a -> 'b set -> 'a | |
1412 | val map_set : ('a -> 'b) -> 'a set -> 'b set | |
1413 | ||
1414 | val member_set : 'a -> 'a set -> bool | |
1415 | val find_set : ('a -> bool) -> 'a list -> 'a | |
1416 | ||
1417 | val sort_set : ('a -> 'a -> int) -> 'a list -> 'a list | |
1418 | ||
1419 | val iter_set : ('a -> unit) -> 'a list -> unit | |
1420 | ||
1421 | val top_set : 'a set -> 'a | |
1422 | ||
1423 | val inter_set : 'a set -> 'a set -> 'a set | |
1424 | val union_set : 'a set -> 'a set -> 'a set | |
1425 | val minus_set : 'a set -> 'a set -> 'a set | |
1426 | ||
1427 | val union_all : ('a set) list -> 'a set | |
1428 | ||
1429 | val big_union_set : ('a -> 'b set) -> 'a set -> 'b set | |
1430 | val card_set : 'a set -> int | |
1431 | ||
1432 | val include_set : 'a set -> 'a set -> bool | |
1433 | val equal_set : 'a set -> 'a set -> bool | |
1434 | val include_set_strict : 'a set -> 'a set -> bool | |
1435 | ||
1436 | (* could put them in Common.Infix *) | |
1437 | val ( $*$ ) : 'a set -> 'a set -> 'a set | |
1438 | val ( $+$ ) : 'a set -> 'a set -> 'a set | |
1439 | val ( $-$ ) : 'a set -> 'a set -> 'a set | |
1440 | ||
1441 | val ( $?$ ) : 'a -> 'a set -> bool | |
1442 | val ( $<$ ) : 'a set -> 'a set -> bool | |
1443 | val ( $<=$ ) : 'a set -> 'a set -> bool | |
1444 | val ( $=$ ) : 'a set -> 'a set -> bool | |
1445 | ||
1446 | val ( $@$ ) : 'a list -> 'a list -> 'a list | |
1447 | ||
1448 | val nub : 'a list -> 'a list | |
1449 | ||
1450 | (* use internally a hash and return | |
1451 | * - the common part, | |
1452 | * - part only in a, | |
1453 | * - part only in b | |
1454 | *) | |
1455 | val diff_two_say_set_eff : 'a list -> 'a list -> | |
1456 | 'a list * 'a list * 'a list | |
1457 | ||
1458 | (*****************************************************************************) | |
1459 | (* Set as normal list *) | |
1460 | (*****************************************************************************) | |
1461 | ||
1462 | (* cf above *) | |
1463 | ||
1464 | (*****************************************************************************) | |
1465 | (* Set as sorted list *) | |
1466 | (*****************************************************************************) | |
1467 | ||
1468 | ||
1469 | (*****************************************************************************) | |
1470 | (* Sets specialized *) | |
1471 | (*****************************************************************************) | |
1472 | ||
1473 | (* | |
1474 | module StringSet = Set.Make(struct type t = string let compare = compare end) | |
1475 | *) | |
1476 | ||
1477 | ||
1478 | (*****************************************************************************) | |
1479 | (* Assoc. But have a look too at Mapb.mli; it's better. Or use Hashtbl. *) | |
1480 | (*****************************************************************************) | |
1481 | ||
1482 | type ('a, 'b) assoc = ('a * 'b) list | |
1483 | ||
b1b2de81 | 1484 | val assoc_to_function : (* Eq a *) ('a, 'b) assoc -> ('a -> 'b) |
34e49164 C |
1485 | |
1486 | val empty_assoc : ('a, 'b) assoc | |
1487 | val fold_assoc : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a | |
1488 | val insert_assoc : 'a -> 'a list -> 'a list | |
1489 | val map_assoc : ('a -> 'b) -> 'a list -> 'b list | |
1490 | val filter_assoc : ('a -> bool) -> 'a list -> 'a list | |
1491 | ||
1492 | val assoc : 'a -> ('a * 'b) list -> 'b | |
1493 | ||
1494 | val keys : ('a * 'b) list -> 'a list | |
1495 | val lookup : 'a -> ('a * 'b) list -> 'b | |
1496 | ||
1497 | val del_assoc : 'a -> ('a * 'b) list -> ('a * 'b) list | |
1498 | val replace_assoc : 'a * 'b -> ('a * 'b) list -> ('a * 'b) list | |
1499 | val apply_assoc : 'a -> ('b -> 'b) -> ('a * 'b) list -> ('a * 'b) list | |
1500 | ||
1501 | val big_union_assoc : ('a -> 'b set) -> 'a list -> 'b set | |
1502 | ||
1503 | val assoc_reverse : ('a * 'b) list -> ('b * 'a) list | |
1504 | val assoc_map : ('a * 'b) list -> ('a * 'b) list -> ('a * 'a) list | |
1505 | ||
1506 | val lookup_list : 'a -> ('a, 'b) assoc list -> 'b | |
1507 | val lookup_list2 : 'a -> ('a, 'b) assoc list -> 'b * int | |
1508 | ||
1509 | val assoc_option : 'a -> ('a, 'b) assoc -> 'b option | |
485bce71 | 1510 | val assoc_with_err_msg : 'a -> ('a, 'b) assoc -> 'b |
34e49164 | 1511 | |
113803cf C |
1512 | val sort_by_val_lowfirst: ('a,'b) assoc -> ('a * 'b) list |
1513 | val sort_by_val_highfirst: ('a,'b) assoc -> ('a * 'b) list | |
1514 | ||
1515 | val sort_by_key_lowfirst: (int,'b) assoc -> (int * 'b) list | |
1516 | val sort_by_key_highfirst: (int,'b) assoc -> (int * 'b) list | |
91eba41f | 1517 | |
0708f913 C |
1518 | val sortgen_by_key_lowfirst: ('a,'b) assoc -> ('a * 'b) list |
1519 | val sortgen_by_key_highfirst: ('a,'b) assoc -> ('a * 'b) list | |
1520 | ||
34e49164 C |
1521 | (*****************************************************************************) |
1522 | (* Assoc, specialized. *) | |
1523 | (*****************************************************************************) | |
1524 | ||
1525 | module IntMap : | |
1526 | sig | |
1527 | type key = int | |
1528 | type +'a t | |
1529 | val empty : 'a t | |
1530 | val is_empty : 'a t -> bool | |
1531 | val add : key -> 'a -> 'a t -> 'a t | |
1532 | val find : key -> 'a t -> 'a | |
1533 | val remove : key -> 'a t -> 'a t | |
1534 | val mem : key -> 'a t -> bool | |
1535 | val iter : (key -> 'a -> unit) -> 'a t -> unit | |
1536 | val map : ('a -> 'b) -> 'a t -> 'b t | |
1537 | val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t | |
1538 | val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b | |
1539 | val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int | |
1540 | val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool | |
1541 | end | |
1542 | val intmap_to_list : 'a IntMap.t -> (IntMap.key * 'a) list | |
1543 | val intmap_string_of_t : 'a -> 'b -> string | |
1544 | ||
1545 | module IntIntMap : | |
1546 | sig | |
1547 | type key = int * int | |
1548 | type +'a t | |
1549 | val empty : 'a t | |
1550 | val is_empty : 'a t -> bool | |
1551 | val add : key -> 'a -> 'a t -> 'a t | |
1552 | val find : key -> 'a t -> 'a | |
1553 | val remove : key -> 'a t -> 'a t | |
1554 | val mem : key -> 'a t -> bool | |
1555 | val iter : (key -> 'a -> unit) -> 'a t -> unit | |
1556 | val map : ('a -> 'b) -> 'a t -> 'b t | |
1557 | val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t | |
1558 | val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b | |
1559 | val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int | |
1560 | val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool | |
1561 | end | |
1562 | val intintmap_to_list : 'a IntIntMap.t -> (IntIntMap.key * 'a) list | |
1563 | val intintmap_string_of_t : 'a -> 'b -> string | |
1564 | ||
1565 | ||
1566 | (*****************************************************************************) | |
1567 | (* Hash *) | |
1568 | (*****************************************************************************) | |
1569 | ||
1570 | (* Note that Hashtbl keep old binding to a key so if want a hash | |
1571 | * of a list, then can use the Hashtbl as is. Use Hashtbl.find_all then | |
1572 | * to get the list of bindings | |
1573 | * | |
1574 | * Note that Hashtbl module use different convention :( the object is | |
1575 | * the first argument, not last as for List or Map. | |
1576 | *) | |
1577 | ||
1578 | (* obsolete: can use directly the Hashtbl module *) | |
1579 | val hcreate : unit -> ('a, 'b) Hashtbl.t | |
1580 | val hadd : 'a * 'b -> ('a, 'b) Hashtbl.t -> unit | |
1581 | val hmem : 'a -> ('a, 'b) Hashtbl.t -> bool | |
1582 | val hfind : 'a -> ('a, 'b) Hashtbl.t -> 'b | |
1583 | val hreplace : 'a * 'b -> ('a, 'b) Hashtbl.t -> unit | |
1584 | val hiter : ('a -> 'b -> unit) -> ('a, 'b) Hashtbl.t -> unit | |
1585 | val hfold : ('a -> 'b -> 'c -> 'c) -> ('a, 'b) Hashtbl.t -> 'c -> 'c | |
1586 | val hremove : 'a -> ('a, 'b) Hashtbl.t -> unit | |
1587 | ||
1588 | ||
1589 | val hfind_default : 'a -> (unit -> 'b) -> ('a, 'b) Hashtbl.t -> 'b | |
1590 | val hfind_option : 'a -> ('a, 'b) Hashtbl.t -> 'b option | |
1591 | val hupdate_default : | |
1592 | 'a -> ('b -> 'b) -> (unit -> 'b) -> ('a, 'b) Hashtbl.t -> unit | |
1593 | ||
1594 | val hash_to_list : ('a, 'b) Hashtbl.t -> ('a * 'b) list | |
1595 | val hash_to_list_unsorted : ('a, 'b) Hashtbl.t -> ('a * 'b) list | |
1596 | val hash_of_list : ('a * 'b) list -> ('a, 'b) Hashtbl.t | |
1597 | ||
1598 | ||
1599 | val hkeys : ('a, 'b) Hashtbl.t -> 'a list | |
1600 | ||
1601 | (*****************************************************************************) | |
1602 | (* Hash sets *) | |
1603 | (*****************************************************************************) | |
1604 | ||
1605 | type 'a hashset = ('a, bool) Hashtbl.t | |
1606 | ||
1607 | ||
1608 | (* common use of hashset, in a hash of hash *) | |
1609 | val hash_hashset_add : 'a -> 'b -> ('a, 'b hashset) Hashtbl.t -> unit | |
1610 | ||
1611 | val hashset_to_set : | |
1612 | < fromlist : ('a ) list -> 'c; .. > -> ('a, 'b) Hashtbl.t -> 'c | |
1613 | ||
1614 | val hashset_to_list : 'a hashset -> 'a list | |
1615 | val hashset_of_list : 'a list -> 'a hashset | |
1616 | ||
1617 | ||
1618 | (*****************************************************************************) | |
1619 | (* Stack *) | |
1620 | (*****************************************************************************) | |
1621 | ||
1622 | type 'a stack = 'a list | |
1623 | val empty_stack : 'a stack | |
1624 | val push : 'a -> 'a stack -> 'a stack | |
1625 | val top : 'a stack -> 'a | |
1626 | val pop : 'a stack -> 'a stack | |
1627 | ||
91eba41f C |
1628 | val top_option: 'a stack -> 'a option |
1629 | ||
34e49164 C |
1630 | val push2 : 'a -> 'a stack ref -> unit |
1631 | val pop2: 'a stack ref -> 'a | |
1632 | ||
91eba41f C |
1633 | (*****************************************************************************) |
1634 | (* Stack with undo/redo support *) | |
1635 | (*****************************************************************************) | |
1636 | ||
1637 | type 'a undo_stack = 'a list * 'a list | |
1638 | val empty_undo_stack : 'a undo_stack | |
1639 | val push_undo : 'a -> 'a undo_stack -> 'a undo_stack | |
1640 | val top_undo : 'a undo_stack -> 'a | |
1641 | val pop_undo : 'a undo_stack -> 'a undo_stack | |
1642 | val redo_undo: 'a undo_stack -> 'a undo_stack | |
1643 | val undo_pop: 'a undo_stack -> 'a undo_stack | |
1644 | ||
1645 | val top_undo_option: 'a undo_stack -> 'a option | |
1646 | ||
34e49164 C |
1647 | |
1648 | (*****************************************************************************) | |
1649 | (* Binary tree *) | |
1650 | (*****************************************************************************) | |
1651 | type 'a bintree = Leaf of 'a | Branch of ('a bintree * 'a bintree) | |
1652 | ||
1653 | (*****************************************************************************) | |
1654 | (* N-ary tree *) | |
1655 | (*****************************************************************************) | |
1656 | ||
1657 | (* no empty tree, must have one root at least *) | |
1658 | type 'a tree = Tree of 'a * ('a tree) list | |
1659 | ||
1660 | val tree_iter : ('a -> unit) -> 'a tree -> unit | |
1661 | ||
1662 | ||
1663 | (*****************************************************************************) | |
1664 | (* N-ary tree with updatable childrens *) | |
1665 | (*****************************************************************************) | |
1666 | ||
b1b2de81 C |
1667 | (* no empty tree, must have one root at least *) |
1668 | type 'a treeref = | |
1669 | | NodeRef of 'a * 'a treeref list ref | |
34e49164 C |
1670 | |
1671 | val treeref_node_iter: | |
b1b2de81 | 1672 | (('a * 'a treeref list ref) -> unit) -> 'a treeref -> unit |
34e49164 | 1673 | val treeref_node_iter_with_parents: |
b1b2de81 C |
1674 | (('a * 'a treeref list ref) -> ('a list) -> unit) -> |
1675 | 'a treeref -> unit | |
34e49164 C |
1676 | |
1677 | val find_treeref: | |
b1b2de81 C |
1678 | (('a * 'a treeref list ref) -> bool) -> |
1679 | 'a treeref -> 'a treeref | |
1680 | ||
1681 | val treeref_children_ref: | |
1682 | 'a treeref -> 'a treeref list ref | |
1683 | ||
1684 | val find_treeref_with_parents_some: | |
1685 | ('a * 'a treeref list ref -> 'a list -> 'c option) -> | |
1686 | 'a treeref -> 'c | |
1687 | ||
1688 | val find_multi_treeref_with_parents_some: | |
1689 | ('a * 'a treeref list ref -> 'a list -> 'c option) -> | |
1690 | 'a treeref -> 'c list | |
1691 | ||
1692 | ||
1693 | (* Leaf can seem redundant, but sometimes want to directly see if | |
1694 | * a children is a leaf without looking if the list is empty. | |
1695 | *) | |
1696 | type ('a, 'b) treeref2 = | |
1697 | | NodeRef2 of 'a * ('a, 'b) treeref2 list ref | |
1698 | | LeafRef2 of 'b | |
1699 | ||
1700 | ||
1701 | val find_treeref2: | |
1702 | (('a * ('a, 'b) treeref2 list ref) -> bool) -> | |
1703 | ('a, 'b) treeref2 -> ('a, 'b) treeref2 | |
1704 | ||
1705 | val treeref_node_iter_with_parents2: | |
1706 | (('a * ('a, 'b) treeref2 list ref) -> ('a list) -> unit) -> | |
1707 | ('a, 'b) treeref2 -> unit | |
1708 | ||
1709 | val treeref_node_iter2: | |
1710 | (('a * ('a, 'b) treeref2 list ref) -> unit) -> ('a, 'b) treeref2 -> unit | |
1711 | ||
1712 | (* | |
1713 | ||
34e49164 | 1714 | |
91eba41f | 1715 | val treeref_children_ref: ('a, 'b) treeref -> ('a, 'b) treeref list ref |
34e49164 | 1716 | |
91eba41f C |
1717 | val find_treeref_with_parents_some: |
1718 | ('a * ('a, 'b) treeref list ref -> 'a list -> 'c option) -> | |
1719 | ('a, 'b) treeref -> 'c | |
34e49164 | 1720 | |
91eba41f C |
1721 | val find_multi_treeref_with_parents_some: |
1722 | ('a * ('a, 'b) treeref list ref -> 'a list -> 'c option) -> | |
1723 | ('a, 'b) treeref -> 'c list | |
b1b2de81 | 1724 | *) |
34e49164 C |
1725 | |
1726 | (*****************************************************************************) | |
1727 | (* Graph. But have a look too at Ograph_*.mli; it's better *) | |
1728 | (*****************************************************************************) | |
1729 | ||
1730 | type 'a graph = 'a set * ('a * 'a) set | |
1731 | ||
1732 | val add_node : 'a -> 'a graph -> 'a graph | |
1733 | val del_node : 'a -> 'a graph -> 'a graph | |
1734 | ||
1735 | val add_arc : 'a * 'a -> 'a graph -> 'a graph | |
1736 | val del_arc : 'a * 'a -> 'a graph -> 'a graph | |
1737 | ||
1738 | val successors : 'a -> 'a graph -> 'a set | |
1739 | val predecessors : 'a -> 'a graph -> 'a set | |
1740 | ||
1741 | val nodes : 'a graph -> 'a set | |
1742 | ||
1743 | val fold_upward : ('a -> 'b -> 'a) -> 'b set -> 'a -> 'b graph -> 'a | |
1744 | ||
1745 | val empty_graph : 'a list * 'b list | |
1746 | ||
1747 | ||
1748 | (*****************************************************************************) | |
1749 | (* Generic op *) | |
1750 | (*****************************************************************************) | |
1751 | ||
1752 | (* mostly alias to functions in List *) | |
1753 | ||
1754 | val map : ('a -> 'b) -> 'a list -> 'b list | |
1755 | val filter : ('a -> bool) -> 'a list -> 'a list | |
1756 | val fold : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a | |
1757 | ||
1758 | val member : 'a -> 'a list -> bool | |
1759 | ||
1760 | val iter : ('a -> unit) -> 'a list -> unit | |
1761 | ||
1762 | val find : ('a -> bool) -> 'a list -> 'a | |
1763 | ||
1764 | val exists : ('a -> bool) -> 'a list -> bool | |
1765 | val forall : ('a -> bool) -> 'a list -> bool | |
1766 | ||
1767 | val big_union : ('a -> 'b set) -> 'a list -> 'b set | |
1768 | ||
1769 | (* same than [] but easier to search for, because [] can also be a pattern *) | |
1770 | val empty_list : 'a list | |
1771 | ||
1772 | val sort : ('a -> 'a -> int) -> 'a list -> 'a list | |
1773 | ||
1774 | val length : 'a list -> int | |
1775 | ||
1776 | val null : 'a list -> bool | |
1777 | ||
1778 | val head : 'a list -> 'a | |
1779 | val tail : 'a list -> 'a list | |
1780 | ||
1781 | val is_singleton : 'a list -> bool | |
1782 | ||
1783 | ||
1784 | ||
1785 | ||
1786 | ||
1787 | ||
1788 | ||
1789 | ||
1790 | ||
1791 | (*###########################################################################*) | |
1792 | (* And now misc functions *) | |
1793 | (*###########################################################################*) | |
1794 | ||
1795 | (*****************************************************************************) | |
1796 | (* DB (LFS) *) | |
1797 | (*****************************************************************************) | |
1798 | ||
1799 | (* cf oassocbdb.ml or oassocdbm.ml *) | |
1800 | ||
1801 | (*****************************************************************************) | |
1802 | (* GUI (LFS, CComment, otimetracker) *) | |
1803 | (*****************************************************************************) | |
1804 | ||
1805 | (* cf ocamlgtk and my gui.ml *) | |
1806 | ||
1807 | ||
1808 | (*****************************************************************************) | |
1809 | (* Graphics (otimetracker) *) | |
1810 | (*****************************************************************************) | |
1811 | ||
1812 | (* cf ocamlgl and my opengl.ml *) | |
1813 | ||
1814 | ||
1815 | ||
1816 | (*****************************************************************************) | |
1817 | (* Geometry (ICFP raytracer) *) | |
1818 | (*****************************************************************************) | |
1819 | ||
1820 | type vector = float * float * float | |
1821 | ||
1822 | type point = vector | |
1823 | type color = vector | |
1824 | ||
1825 | val dotproduct : vector * vector -> float | |
1826 | ||
1827 | val vector_length : vector -> float | |
1828 | ||
1829 | val minus_point : point * point -> vector | |
1830 | ||
1831 | val distance : point * point -> float | |
1832 | ||
1833 | val normalise : vector -> vector | |
1834 | ||
1835 | val mult_coeff : vector -> float -> vector | |
1836 | ||
1837 | val add_vector : vector -> vector -> vector | |
1838 | val mult_vector : vector -> vector -> vector | |
1839 | val sum_vector : vector list -> vector | |
1840 | ||
1841 | ||
1842 | (*****************************************************************************) | |
1843 | (* Pics (ICFP raytracer) *) | |
1844 | (*****************************************************************************) | |
1845 | type pixel = int * int * int | |
1846 | val write_ppm : int -> int -> pixel list -> filename -> unit | |
1847 | val test_ppm1 : unit -> unit | |
1848 | ||
1849 | (*****************************************************************************) | |
1850 | (* Diff (LFS) *) | |
1851 | (*****************************************************************************) | |
1852 | ||
1853 | type diff = Match | BnotinA | AnotinB | |
1854 | val diff : (int -> int -> diff -> unit) -> string list * string list -> unit | |
1855 | val diff2 : (int -> int -> diff -> unit) -> string * string -> unit | |
1856 | ||
1857 | (*****************************************************************************) | |
1858 | (* Parsers (aop-colcombet) *) | |
1859 | (*****************************************************************************) | |
1860 | ||
1861 | val parserCommon : Lexing.lexbuf -> ('a -> Lexing.lexbuf -> 'b) -> 'a -> 'b | |
1862 | val getDoubleParser : | |
1863 | ('a -> Lexing.lexbuf -> 'b) -> 'a -> (string -> 'b) * (string -> 'b) | |
1864 | ||
1865 | (*****************************************************************************) | |
1866 | (* Parsers (cocci) *) | |
1867 | (*****************************************************************************) | |
1868 | ||
1869 | ||
1870 | (* Currently lexing.ml does not handle the line number position. | |
1871 | * Even if there is some fields in the lexing structure, they are not | |
1872 | * maintained by the lexing engine :( So the following code does not work: | |
1873 | * | |
1874 | * let pos = Lexing.lexeme_end_p lexbuf in | |
1875 | * sprintf "at file %s, line %d, char %d" pos.pos_fname pos.pos_lnum | |
1876 | * (pos.pos_cnum - pos.pos_bol) in | |
1877 | * | |
1878 | * Hence those functions to overcome the previous limitation. | |
1879 | *) | |
1880 | ||
1881 | type parse_info = { | |
1882 | str: string; | |
1883 | charpos: int; | |
1884 | ||
1885 | line: int; | |
1886 | column: int; | |
1887 | file: filename; | |
1888 | } | |
1889 | val fake_parse_info : parse_info | |
1890 | val string_of_parse_info : parse_info -> string | |
485bce71 | 1891 | val string_of_parse_info_bis : parse_info -> string |
34e49164 C |
1892 | |
1893 | (* array[i] will contain the (line x col) of the i char position *) | |
1894 | val full_charpos_to_pos : filename -> (int * int) array | |
1895 | ||
1896 | (* fill in the line and column field of parse_info that were not set | |
1897 | * during lexing because of limitations of ocamllex. *) | |
1898 | val complete_parse_info : | |
1899 | filename -> (int * int) array -> parse_info -> parse_info | |
1900 | ||
708f4980 C |
1901 | val full_charpos_to_pos_large: |
1902 | filename -> (int -> (int * int)) | |
1903 | ||
1904 | val complete_parse_info_large : | |
1905 | filename -> (int -> (int * int)) -> parse_info -> parse_info | |
1906 | ||
34e49164 C |
1907 | (* return line x col x str_line from a charpos. This function is quite |
1908 | * expensive so don't use it to get the line x col from every token in | |
1909 | * a file. Instead use full_charpos_to_pos. | |
1910 | *) | |
1911 | val info_from_charpos : int -> filename -> (int * int * string) | |
1912 | ||
1913 | val error_message : filename -> (string * int) -> string | |
1914 | val error_message_short : filename -> (string * int) -> string | |
1915 | ||
1916 | (* add a 'decalage/shift' argument to handle stuff such as cpp which includes | |
1917 | * files and who can make shift. | |
1918 | *) | |
1919 | val error_messagebis : filename -> (string * int) -> int -> string | |
1920 | ||
1921 | (*****************************************************************************) | |
1922 | (* Scope managment (cocci) *) | |
1923 | (*****************************************************************************) | |
1924 | ||
1925 | (* for example of use, see the code used in coccinelle *) | |
1926 | type ('a, 'b) scoped_env = ('a, 'b) assoc list | |
1927 | ||
b1b2de81 | 1928 | val lookup_env : (* Eq a *) 'a -> ('a, 'b) scoped_env -> 'b |
34e49164 C |
1929 | val member_env_key : 'a -> ('a, 'b) scoped_env -> bool |
1930 | ||
1931 | val new_scope : ('a, 'b) scoped_env ref -> unit | |
1932 | val del_scope : ('a, 'b) scoped_env ref -> unit | |
1933 | ||
1934 | val do_in_new_scope : ('a, 'b) scoped_env ref -> (unit -> unit) -> unit | |
1935 | ||
1936 | val add_in_scope : ('a, 'b) scoped_env ref -> 'a * 'b -> unit | |
1937 | ||
1938 | ||
1939 | ||
1940 | ||
1941 | (* for example of use, see the code used in coccinelle *) | |
1942 | type ('a, 'b) scoped_h_env = { | |
1943 | scoped_h : ('a, 'b) Hashtbl.t; | |
1944 | scoped_list : ('a, 'b) assoc list; | |
1945 | } | |
1946 | val empty_scoped_h_env : unit -> ('a, 'b) scoped_h_env | |
1947 | val clone_scoped_h_env : ('a, 'b) scoped_h_env -> ('a, 'b) scoped_h_env | |
1948 | ||
1949 | val lookup_h_env : 'a -> ('a, 'b) scoped_h_env -> 'b | |
1950 | val member_h_env_key : 'a -> ('a, 'b) scoped_h_env -> bool | |
1951 | ||
1952 | val new_scope_h : ('a, 'b) scoped_h_env ref -> unit | |
1953 | val del_scope_h : ('a, 'b) scoped_h_env ref -> unit | |
1954 | ||
1955 | val do_in_new_scope_h : ('a, 'b) scoped_h_env ref -> (unit -> unit) -> unit | |
1956 | ||
1957 | val add_in_scope_h : ('a, 'b) scoped_h_env ref -> 'a * 'b -> unit | |
1958 | ||
1959 | (*****************************************************************************) | |
1960 | (* Terminal (LFS) *) | |
1961 | (*****************************************************************************) | |
1962 | ||
91eba41f C |
1963 | (* don't forget to call Common_extra.set_link () *) |
1964 | ||
34e49164 C |
1965 | val _execute_and_show_progress_func : |
1966 | (int (* length *) -> ((unit -> unit) -> unit) -> unit) ref | |
1967 | val execute_and_show_progress : | |
1968 | int (* length *) -> ((unit -> unit) -> unit) -> unit | |
1969 | ||
1970 | (*****************************************************************************) | |
1971 | (* Flags and actions *) | |
1972 | (*****************************************************************************) | |
1973 | ||
1974 | val cmdline_flags_devel : unit -> cmdline_options | |
1975 | val cmdline_flags_verbose : unit -> cmdline_options | |
1976 | val cmdline_flags_other : unit -> cmdline_options | |
1977 | ||
1978 | (*****************************************************************************) | |
1979 | (* Misc/test *) | |
1980 | (*****************************************************************************) | |
1981 | ||
1982 | val generic_print : 'a -> string -> string | |
1983 | ||
1984 | class ['a] olist : | |
1985 | 'a list -> | |
1986 | object | |
1987 | val xs : 'a list | |
1988 | method fold : ('b -> 'a -> 'b) -> 'b -> 'b | |
1989 | method view : 'a list | |
1990 | end | |
1991 | ||
1992 | val typing_sux_test : unit -> unit | |
1993 |