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