1 (*###########################################################################*)
3 (*###########################################################################*)
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.
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++)
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.
22 (*****************************************************************************)
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.
29 (* if set then will not do certain finalize so faster to go back in replay *)
30 val debugger
: bool ref
32 type prof
= PALL
| PNONE
| PSOME
of string list
33 val profile
: prof
ref
34 val show_trace_profile
: bool ref
37 val verbose_level
: int ref
39 (* forbid pr2_once to do the once "optimisation" *)
40 val disable_pr2_once
: bool ref
44 (* works with new_temp_file *)
45 val save_tmp_files
: bool ref
49 (*****************************************************************************)
50 (* Module side effect *)
51 (*****************************************************************************)
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 .
58 (*****************************************************************************)
60 (*****************************************************************************)
61 (* cf the _xxx variables in this file *)
63 (*###########################################################################*)
65 (*###########################################################################*)
67 type filename
= string
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.
74 module BasicType
: sig
75 type filename
= string
78 (* Same spirit. Trick found in Jane Street core lib, but originated somewhere
79 * else I think: the ability to open nested modules. *)
81 val ( +> ) : 'a
-> ('a
-> 'b
) -> 'b
82 val ( =~
) : string -> string -> bool
83 val ( ==~
) : string -> Str.regexp
-> bool
88 * Another related trick, found via Jon Harrop to have an extended standard
89 * lib is to do something like
91 * module List = struct
96 * And then can put this "module extension" somewhere to open it.
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).
109 (*****************************************************************************)
110 (* Debugging/logging *)
111 (*****************************************************************************)
113 val _tab_level_print
: int ref
114 val indent_do
: (unit -> 'a
) -> 'a
115 val reset_pr_indent
: unit -> unit
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
121 * The use of 2 in pr2 is because 2 is under UNIX the second descriptor
122 * which corresponds to stderr.
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
132 (* use Dumper.dump *)
133 val pr2_gen
: 'a
-> unit
134 val dump
: 'a
-> string
136 (* see flag: val disable_pr2_once : bool ref *)
137 val _already_printed
: (string, bool) Hashtbl.t
138 val pr2_once
: string -> unit
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
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
150 val spf
: ('a
, unit, string) format
-> 'a
152 (* default = stderr *)
153 val _chan
: out_channel
ref
154 (* generate & use a /tmp/debugml-xxx file *)
155 val start_log_file
: unit -> unit
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
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
168 val pause
: unit -> unit
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
176 val print_n
: int -> string -> unit
177 val printerr_n
: int -> string -> unit
179 val _debug
: bool ref
180 val debugon
: unit -> unit
181 val debugoff
: unit -> unit
182 val debug
: (unit -> unit) -> unit
184 (* see flag: val debugger : bool ref *)
187 (*****************************************************************************)
188 (* Profiling (cpu/mem) *)
189 (*****************************************************************************)
191 val get_mem
: unit -> unit
192 val memory_stat
: unit -> string
194 val timenow
: unit -> string
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
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
209 val time_func
: (unit -> 'a
) -> 'a
213 (* see flag: type prof = PALL | PNONE | PSOME of string list *)
214 (* see flag: val profile : prof ref *)
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
220 val profile_code_exclusif
: string -> (unit -> 'a
) -> 'a
221 val profile_code_inside_exclusif_ok
: string -> (unit -> 'a
) -> 'a
223 val report_if_take_time
: int -> string -> (unit -> 'a
) -> 'a
225 (* similar to profile_code but print some information during execution too *)
226 val profile_code2
: string -> (unit -> 'a
) -> 'a
228 (*****************************************************************************)
230 (*****************************************************************************)
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
238 val _list_bool
: (string * bool) list
ref
239 val example3
: string -> bool -> unit
240 val test_all
: unit -> unit
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
256 (* quickcheck spirit *)
257 type 'a gen
= unit -> 'a
259 (* quickcheck random generators *)
261 val lg
: 'a gen
-> 'a list gen
262 val pg
: 'a gen
-> 'b gen
-> ('a
* 'b
) gen
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
272 val laws
: string -> ('a
-> bool) -> 'a gen
-> 'a
option
275 * let b = laws "unit" (fun x -> reverse [x] = [x]) ig
278 val statistic_number
: 'a list
-> (int * 'a
) list
279 val statistic
: 'a list
-> (int * 'a
) list
282 string -> ('a
-> bool * '
b) -> 'a gen
-> 'a
option * (int * '
b) list
284 (*****************************************************************************)
286 (*****************************************************************************)
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
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
298 (*****************************************************************************)
300 (*****************************************************************************)
301 val _counter
: int ref
302 val _counter2
: int ref
303 val _counter3
: int ref
305 val counter
: unit -> int
306 val counter2
: unit -> int
307 val counter3
: unit -> int
311 (*****************************************************************************)
312 (* String_of and (pretty) printing *)
313 (*****************************************************************************)
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
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
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
332 (* convert something printed using Format to print into a string *)
333 val format_to_string
: (unit -> unit) (* printer *) -> string
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
343 val mk_str_func_of_assoc_conv
:
344 ('a
* string) list
-> (string -> 'a
) * ('a
-> string)
346 (*****************************************************************************)
348 (*****************************************************************************)
350 (* was working with my macro.ml4 *)
351 val macro_expand
: string -> unit
353 (*****************************************************************************)
354 (* Composition/Control *)
355 (*****************************************************************************)
357 val ( +> ) : 'a
-> ('a
-> '
b) -> '
b
358 val ( +!> ) : 'a
ref -> ('a
-> 'a
) -> unit
359 val ( $
) : ('a
-> '
b) -> ('
b -> 'c
) -> 'a
-> 'c
361 val compose
: ('a
-> '
b) -> ('c
-> 'a
) -> 'c
-> '
b
362 val flip
: ('a
-> '
b -> 'c
) -> '
b -> 'a
-> 'c
364 val curry
: ('a
* '
b -> 'c
) -> 'a
-> '
b -> 'c
365 val uncurry
: ('a
-> '
b -> 'c
) -> 'a
* '
b -> 'c
368 val do_nothing
: unit -> unit
370 val forever
: (unit -> unit) -> unit
372 val applyn
: int -> ('a
-> 'a
) -> 'a
-> 'a
374 class ['a
] shared_variable_hook
:
377 val mutable data
: 'a
378 val mutable registered
: (unit -> unit) list
380 method modify
: ('a
-> 'a
) -> unit
381 method register
: (unit -> unit) -> unit
382 method set
: 'a
-> unit
385 val fixpoint
: ('a
-> 'a
) -> 'a
-> 'a
386 val fixpoint_for_object
: ((< equal
: 'a
-> bool; .. > as 'a
) -> 'a
) -> 'a
-> 'a
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
392 type 'a mylazy
= (unit -> 'a
)
395 val save_excursion
: 'a
ref -> (unit -> '
b) -> '
b
398 val unwind_protect
: (unit -> 'a
) -> (exn
-> '
b) -> 'a
401 val finalize
: (unit -> 'a
) -> (unit -> '
b) -> 'a
403 val memoized
: ('a
, '
b) Hashtbl.t
-> 'a
-> (unit -> '
b) -> '
b
405 val cache_in_ref
: 'a
option ref -> (unit -> 'a
) -> 'a
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
412 val cache_computation
:
413 ?verbose
:bool -> ?use_cache
:bool -> filename
-> string (* extension *) ->
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.
419 val cache_computation_robust
:
421 string (* extension for marshalled object *) ->
422 (filename list
* 'x
) ->
423 string (* extension for marshalled dependencies *) ->
429 val once
: ('a
-> unit) -> ('a
-> unit)
431 val before_leaving
: ('a
-> unit) -> 'a
-> 'a
433 (* do some finalize, signal handling, unix exit conversion, etc *)
434 val main_boilerplate
: (unit -> unit) -> unit
437 (* cf also the timeout function below that are control related too *)
440 (*****************************************************************************)
442 (*****************************************************************************)
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
449 (*****************************************************************************)
450 (* Error managment *)
451 (*****************************************************************************)
457 exception Multi_found
459 exception WrongFormat
of string
462 val internal_error
: string -> 'a
463 val myassert
: bool -> unit
464 val warning
: string -> 'a
-> 'a
465 val error_cant_have
: 'a
-> '
b
467 val exn_to_s
: exn
-> string
469 val string_of_exn
: exn
-> string
471 type error
= Error
of string
476 (*****************************************************************************)
478 (*****************************************************************************)
480 val check_stack_size
: int -> unit
481 val check_stack_nbfiles
: int -> unit
483 (* internally common.ml set Gc. parameters *)
484 val _init_gc_stack
: unit
486 (*****************************************************************************)
487 (* Arguments and command line *)
488 (*****************************************************************************)
490 type arg_spec_full
= Arg.key
* Arg.spec
* Arg.doc
491 type cmdline_options
= arg_spec_full list
494 type options_with_title
= string * string * arg_spec_full list
495 type cmdline_sections
= options_with_title list
498 (* A wrapper around Arg modules that have more logical argument order,
499 * and returns the remaining args.
502 cmdline_options
-> Arg.usage_msg
-> string array
-> string list
504 (* Another wrapper that does Arg.align automatically *)
505 val usage
: Arg.usage_msg
-> cmdline_options
-> unit
509 (* Work with the options_with_title type way to organize a long
510 * list of command line switches.
513 Arg.usage_msg
-> short_opt
:cmdline_options
-> unit
515 Arg.usage_msg
-> short_opt
:cmdline_options
-> long_opt
:cmdline_sections
->
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.
521 val arg_align2
: cmdline_options
-> cmdline_options
523 cmdline_options
-> Arg.usage_msg
-> (unit -> unit) (* short_usage func *) ->
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)
536 type cmdline_actions
= action_spec list
537 exception WrongNumberOfArguments
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
544 val mk_action_n_arg
: (string list
-> unit) -> action_func
546 val options_of_actions
:
547 string ref (* the action ref *) -> cmdline_actions
-> cmdline_options
549 cmdline_actions
-> Arg.key list
551 Arg.key
-> string list
(* args *) -> cmdline_actions
-> unit
553 (*****************************************************************************)
555 (*****************************************************************************)
557 (* Using the generic (=) is tempting, but it backfires, so better avoid it *)
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.
568 val (=|=) : int -> int -> bool
569 val (=<=) : char
-> char
-> bool
570 val (=$
=) : string -> string -> bool
571 val (=:=) : bool -> bool -> bool
573 val (=*=): 'a
-> 'a
-> bool
575 (* if want to restrict the use of '=', uncomment this:
577 * val (=): unit -> unit -> bool
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 (=)
585 (*###########################################################################*)
586 (* And now basic types *)
587 (*###########################################################################*)
589 (*****************************************************************************)
591 (*****************************************************************************)
593 val ( ||| ) : 'a
-> 'a
-> 'a
594 val ( ==> ) : bool -> bool -> bool
595 val xor
: 'a
-> 'a
-> bool
599 (*****************************************************************************)
601 (*****************************************************************************)
603 val string_of_char
: char
-> string
604 val string_of_chars
: char list
-> string
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
614 val cbetween
: char
-> char
-> char
-> bool
616 (*****************************************************************************)
618 (*****************************************************************************)
620 val ( /! ) : int -> int -> int
622 val do_n
: int -> (unit -> unit) -> unit
623 val foldn
: ('a
-> int -> 'a
) -> 'a
-> int -> 'a
629 val deg_to_rad
: float -> float
631 val clampf
: float -> float
633 val square
: float -> float
634 val power
: int -> int -> int
636 val between
: 'a
-> 'a
-> 'a
-> bool
637 val between_strict
: int -> int -> int -> bool
638 val bitrange
: int -> int -> bool
640 val prime1
: int -> int option
641 val prime
: int -> int option
643 val sum
: int list
-> int
644 val product
: int list
-> int
646 val decompose
: int -> int list
648 val mysquare
: int -> int
649 val sqr
: float -> float
651 type compare
= Equal
| Inf
| Sup
652 val ( <=> ) : 'a
-> 'a
-> compare
653 val ( <==> ) : 'a
-> 'a
-> int
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
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.
667 val ( += ) : int ref -> int -> unit
668 val ( -= ) : int ref -> int -> unit
670 val pourcent
: int -> int -> int
671 val pourcent_float
: int -> int -> float
672 val pourcent_float_of_floats
: float -> float -> float
674 val pourcent_good_bad
: int -> int -> int
675 val pourcent_good_bad_float
: int -> int -> float
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 (*****************************************************************************)
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
692 val numd_int
: int numdict
693 val numd_float
: float numdict
695 val testd
: 'a numdict
-> 'a
-> 'a
698 module ArithFloatInfix
: sig
699 val (+) : float -> float -> float
700 val (-) : float -> float -> float
701 val (/) : float -> float -> float
702 val ( * ) : float -> float -> float
705 val (+..) : int -> int -> int
706 val (-..) : int -> int -> int
707 val (/..) : int -> int -> int
708 val ( *..) : int -> int -> int
710 val (+=) : float ref -> float -> unit
713 (*****************************************************************************)
715 (*****************************************************************************)
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
723 (*****************************************************************************)
725 (*****************************************************************************)
727 type 'a pair
= 'a
* 'a
728 type 'a triple
= 'a
* 'a
* 'a
730 val fst3
: 'a
* '
b * 'c
-> 'a
731 val snd3
: 'a
* '
b * 'c
-> '
b
732 val thd3
: 'a
* '
b * 'c
-> 'c
734 val sndthd
: 'a
* '
b * 'c
-> '
b * 'c
736 val map_fst
: ('a
-> '
b) -> 'a
* 'c
-> '
b * 'c
737 val map_snd
: ('a
-> '
b) -> 'c
* 'a
-> 'c
* '
b
739 val pair
: ('a
-> '
b) -> 'a
* 'a
-> '
b * '
b
741 val snd
: 'a
* '
b -> '
b (* alias *)
742 val fst
: 'a
* '
b -> 'a
(* alias *)
744 val double
: 'a
-> 'a
* 'a
745 val swap
: 'a
* '
b -> '
b * 'a
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
755 (*****************************************************************************)
757 (*****************************************************************************)
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
762 val just
: 'a
option -> 'a
763 val some
: 'a
option -> 'a
(* alias *)
765 val fmap
: ('a
-> '
b) -> 'a
option -> '
b option
766 val map_option
: ('a
-> '
b) -> 'a
option -> '
b option (* alias *)
768 val do_option
: ('a
-> unit) -> 'a
option -> unit
770 val optionise
: (unit -> 'a
) -> 'a
option
772 val some_or
: 'a
option -> 'a
-> 'a
774 val partition_either
:
775 ('a
-> ('
b, 'c
) either
) -> 'a list
-> '
b list
* 'c list
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
781 val list_to_single_or_exn
: 'a list
-> 'a
783 (*****************************************************************************)
785 (*****************************************************************************)
786 type bool3
= True3
| False3
| TrueFalsePb3
of string
789 (*****************************************************************************)
791 (*****************************************************************************)
793 val slength
: string -> int (* alias *)
794 val concat
: string -> string list
-> string (* alias *)
796 val i_to_s
: int -> string
797 val s_to_i
: string -> int
799 (* strings take space in memory. Better when can share the space used by
802 val _shareds
: (string, string) Hashtbl.t
803 val shared_string
: string -> string
805 val chop
: string -> string
806 val chop_dirsymbol
: string -> string
808 val ( <!!> ) : string -> int * int -> string
809 val ( <!> ) : string -> int -> char
811 val take_string
: int -> string -> string
812 val take_string_safe
: int -> string -> string
814 val split_on_char
: char
-> string -> string list
816 val lowercase
: string -> string
818 val quote
: string -> string
820 val null_string
: string -> bool
821 val is_blank_string
: string -> bool
822 val is_string_prefix
: string -> string -> bool
825 val plural
: int -> string -> string
827 val showCodeHex
: int list
-> unit
829 val size_mo_ko
: int -> string
830 val size_ko
: int -> string
832 val edit_distance
: string -> string -> int
834 val md5sum_of_string
: string -> string
836 (*****************************************************************************)
838 (*****************************************************************************)
840 val regexp_alpha
: Str.regexp
841 val regexp_word
: Str.regexp
843 val _memo_compiled_regexp
: (string, Str.regexp
) Hashtbl.t
844 val ( =~
) : string -> string -> bool
845 val ( ==~
) : string -> Str.regexp
-> bool
849 val regexp_match
: string -> string -> string
851 val matched
: int -> string -> string
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
862 val string_match_substring
: Str.regexp
-> string -> bool
864 val split
: string (* sep regexp *) -> string -> string list
865 val join
: string (* sep *) -> string list
-> string
867 val split_list_regexp
: string -> string list
-> (string * string list
) list
869 val all_match
: string (* regexp *) -> string -> string list
870 val global_replace_regexp
:
871 string (* regexp *) -> (string -> string) -> string -> string
873 val regular_words
: string -> string list
874 val contain_regular_word
: string -> bool
876 (*****************************************************************************)
878 (*****************************************************************************)
880 (* now at beginning of this file: type filename = string *)
881 val dirname
: string -> string
882 val basename
: string -> string
884 val filesuffix
: filename
-> string
885 val fileprefix
: filename
-> string
887 val adjust_ext_if_needed
: filename
-> string -> filename
889 (* db for dir, base *)
890 val db_of_filename
: filename
-> (string * filename
)
891 val filename_of_db
: (string * filename
) -> filename
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
900 val filename_of_dbe
: string * string * string -> filename
902 (* ex: replace_ext "toto.c" "c" "var" *)
903 val replace_ext
: filename
-> string -> string -> filename
905 (* remove the ., .. *)
906 val normalize_path
: filename
-> filename
908 val relative_to_absolute
: filename
-> filename
910 val is_relative
: filename
-> bool
911 val is_absolute
: filename
-> bool
913 val filename_without_leading_path
: string -> filename
-> filename
915 (*****************************************************************************)
917 (*****************************************************************************)
923 (*****************************************************************************)
925 (*****************************************************************************)
927 (* can also use ocamlcalendar, but heavier, use many modules ... *)
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
935 type date_dmy
= DMY
of day
* month
* year
937 type hour
= Hour
of int
938 type minute
= Min
of int
939 type second
= Sec
of int
941 type time_hms
= HMS
of hour
* minute
* second
943 type full_date
= date_dmy
* time_hms
947 type days
= Days
of int
949 type time_dmy
= TimeDMY
of day
* month
* year
953 type float_time
= float
956 val mk_date_dmy
: int -> int -> int -> date_dmy
959 val check_date_dmy
: date_dmy
-> unit
960 val check_time_dmy
: time_dmy
-> unit
961 val check_time_hms
: time_hms
-> unit
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
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
975 val floattime_of_string
: string -> float_time
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
982 val sec_to_days
: int -> string
983 val sec_to_hours
: int -> string
985 val today
: unit -> float_time
986 val yesterday
: unit -> float_time
987 val tomorrow
: unit -> float_time
989 val lastweek
: unit -> float_time
990 val lastmonth
: unit -> float_time
992 val week_before
: float_time
-> float_time
993 val month_before
: float_time
-> float_time
994 val week_after
: float_time
-> float_time
996 val days_in_week_of_day
: float_time
-> float_time list
998 val first_day_in_week_of_day
: float_time
-> float_time
999 val last_day_in_week_of_day
: float_time
-> float_time
1001 val day_secs
: float_time
1003 val rough_days_since_jesus
: date_dmy
-> days
1004 val rough_days_between_dates
: date_dmy
-> date_dmy
-> days
1006 val string_of_unix_time_lfs
: Unix.tm
-> string
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
1014 (*****************************************************************************)
1015 (* Lines/Words/Strings *)
1016 (*****************************************************************************)
1018 val list_of_string
: string -> char list
1020 val lines
: string -> string list
1021 val unlines
: string list
-> string
1023 val words
: string -> string list
1024 val unwords
: string list
-> string
1026 val split_space
: string -> string list
1028 val lines_with_nl
: string -> string list
1030 val nblines
: string -> int
1032 (*****************************************************************************)
1034 (*****************************************************************************)
1035 val cat
: filename
-> string list
1036 val cat_orig
: filename
-> string list
1037 val cat_array
: filename
-> string array
1039 val uncat
: string list
-> filename
-> unit
1041 val interpolate
: string -> string list
1043 val echo
: string -> string
1045 val usleep
: int -> unit
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
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
1056 val do_in_fork
: (unit -> unit) -> int
1058 val mkdir
: ?mode
:Unix.file_perm
-> string -> unit
1060 val read_file
: filename
-> string
1061 val write_file
: file
:filename
-> string -> unit
1063 val filesize
: filename
-> int
1064 val filemtime
: filename
-> float
1066 val nblines_file
: filename
-> int
1068 val lfile_exists
: filename
-> bool
1069 val is_directory
: filename
-> bool
1071 val capsule_unix
: ('a
-> unit) -> 'a
-> unit
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
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
1089 val sanity_check_files_and_adjust
:
1090 string (* ext *) -> string list
-> filename list
1093 type rwx
= [ `R
| `W
| `X
] list
1094 val file_perm_of
: u
:rwx
-> g
:rwx
-> o
:rwx
-> Unix.file_perm
1096 val has_env
: string -> bool
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
1106 val with_open_stringbuf
:
1107 (((string -> unit) * Buffer.t
) -> unit) -> string
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 | _ -> ...
1116 * The same is true for UnixExit (see below).
1118 val timeout_function
: int -> (unit -> 'a
) -> 'a
1120 val timeout_function_opt
: int option -> (unit -> 'a
) -> 'a
1123 (* creation of /tmp files, a la gcc
1124 * ex: new_temp_file "cocci" ".c" will give "/tmp/cocci-3252-434465.c"
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
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.
1136 * subtil: same problem than with Timeout. Do not intercept such exception
1137 * with some blind try (...) with _ -> ...
1139 exception UnixExit
of int
1140 val exn_to_real_unixexit
: (unit -> 'a
) -> 'a
1149 (*###########################################################################*)
1150 (* And now collection-like types. See also ocollection.mli *)
1151 (*###########################################################################*)
1153 (*****************************************************************************)
1155 (*****************************************************************************)
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
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
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
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
1177 val span
: ('a
-> bool) -> 'a list
-> 'a list
* 'a list
1179 val skip_until
: ('a list
-> bool) -> 'a list
-> 'a list
1180 val skipfirst
: (* Eq a *) 'a
-> 'a list
-> 'a list
1182 (* cf also List.partition *)
1183 val fpartition
: ('a
-> '
b option) -> 'a list
-> '
b list
* 'a list
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
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.
1195 val group_assoc_bykey_eff
: ('a
* '
b) list
-> ('a
* '
b list
) list
1197 val splitAt
: int -> 'a list
-> 'a list
* 'a list
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
1202 val pack
: int -> 'a list
-> 'a list list
1205 val enum
: int -> int -> int list
1206 val repeat
: 'a
-> int -> 'a list
1207 val generate
: int -> 'a
-> 'a list
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
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
1220 val nth
: 'a list
-> int -> 'a
1221 val rang
: (* Eq a *) 'a
-> 'a list
-> int
1223 val last_n
: int -> 'a list
-> 'a list
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
1237 val inits
: 'a list
-> 'a list list
1238 val tails
: 'a list
-> 'a list list
1241 val ( ++ ) : 'a list
-> 'a list
-> 'a list
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
1248 val rev_map
: ('a
-> '
b) -> 'a list
-> '
b list
1250 val join_gen
: 'a
-> 'a list
-> 'a list
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
1257 val collect_accu
: ('a
-> '
b list
) -> '
b list
-> 'a list
-> '
b list
1258 val collect
: ('a
-> '
b list
) -> 'a list
-> '
b list
1260 val remove
: 'a
-> 'a list
-> 'a list
1262 val exclude
: ('a
-> bool) -> 'a list
-> 'a list
1264 (* Not like unix uniq command line tool that only delete contiguous repeated
1265 * line. Here we delete any repeated line (here list element).
1267 val uniq
: 'a list
-> 'a list
1268 val uniq_eff
: 'a list
-> 'a list
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
1274 val doublon
: 'a list
-> bool
1276 val reverse
: 'a list
-> 'a list
(* alias *)
1277 val rev
: 'a list
-> 'a list
(* alias *)
1278 val rotate
: 'a list
-> 'a list
1280 val map_flatten
: ('a
-> '
b list
) -> 'a list
-> '
b list
1282 val map2
: ('a
-> '
b) -> 'a list
-> '
b list
1283 val map3
: ('a
-> '
b) -> 'a list
-> '
b list
1286 val maximum
: 'a list
-> 'a
1287 val minimum
: 'a list
-> 'a
1289 val min_with
: ('a
-> '
b) -> 'a list
-> 'a
1290 val two_mins_with
: ('a
-> '
b) -> 'a list
-> 'a
* 'a
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
1295 val or_list
: bool list
-> bool
1296 val and_list
: bool list
-> bool
1298 val sum_float
: float list
-> float
1299 val sum_int
: int list
-> int
1300 val avg_list
: int list
-> float
1302 val return_when
: ('a
-> '
b option) -> 'a list
-> '
b
1305 val grep_with_previous
: ('a
-> 'a
-> bool) -> 'a list
-> 'a list
1306 val iter_with_previous
: ('a
-> 'a
-> '
b) -> 'a list
-> unit
1308 val iter_with_before_after
:
1309 ('a list
-> 'a
-> 'a list
-> unit) -> 'a list
-> unit
1311 val get_pair
: 'a list
-> ('a
* 'a
) list
1313 val permutation
: 'a list
-> 'a list list
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
1321 val pack_sorted
: ('a
-> 'a
-> bool) -> 'a list
-> 'a list list
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
1327 val cartesian_product
: 'a list
-> '
b list
-> ('a
* '
b) list
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
1337 (*****************************************************************************)
1339 (*****************************************************************************)
1341 val array_find_index
: (int -> bool) -> 'a array
-> int
1342 val array_find_index_via_elem
: ('a
-> bool) -> 'a array
-> int
1344 (* for better type checking, as sometimes when have an 'int array', can
1345 * easily mess up the index from the value.
1347 type idx
= Idx
of int
1348 val next_idx
: idx
-> idx
1349 val int_of_idx
: idx
-> int
1351 val array_find_index_typed
: (idx
-> bool) -> 'a array
-> idx
1353 (*****************************************************************************)
1355 (*****************************************************************************)
1357 type 'a matrix
= 'a array array
1359 val map_matrix
: ('a
-> '
b) -> 'a matrix
-> '
b matrix
1361 val make_matrix_init
:
1362 nrow
:int -> ncolumn
:int -> (int -> int -> 'a
) -> 'a matrix
1365 (int -> int -> 'a
-> unit) -> 'a matrix
-> unit
1367 val nb_rows_matrix
: 'a matrix
-> int
1368 val nb_columns_matrix
: 'a matrix
-> int
1370 val rows_of_matrix
: 'a matrix
-> 'a list list
1371 val columns_of_matrix
: 'a matrix
-> 'a list list
1373 val all_elems_matrix_by_row
: 'a matrix
-> 'a list
1375 (*****************************************************************************)
1377 (*****************************************************************************)
1381 (*****************************************************************************)
1382 (* Set. But have a look too at set*.mli; it's better. Or use Hashtbl. *)
1383 (*****************************************************************************)
1385 type 'a set
= 'a list
1387 val empty_set
: 'a set
1389 val insert_set
: 'a
-> 'a set
-> 'a set
1390 val single_set
: 'a
-> 'a set
1391 val set
: 'a list
-> 'a set
1393 val is_set
: 'a list
-> bool
1395 val exists_set
: ('a
-> bool) -> 'a set
-> bool
1396 val forall_set
: ('a
-> bool) -> 'a set
-> bool
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
1402 val member_set
: 'a
-> 'a set
-> bool
1403 val find_set
: ('a
-> bool) -> 'a list
-> 'a
1405 val sort_set
: ('a
-> 'a
-> int) -> 'a list
-> 'a list
1407 val iter_set
: ('a
-> unit) -> 'a list
-> unit
1409 val top_set
: 'a set
-> 'a
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
1415 val union_all
: ('a set
) list
-> 'a set
1417 val big_union_set
: ('a
-> '
b set
) -> 'a set
-> '
b set
1418 val card_set
: 'a set
-> int
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
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
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
1434 val ( $
@$
) : 'a list
-> 'a list
-> 'a list
1436 val nub
: 'a list
-> 'a list
1438 (* use internally a hash and return
1439 * - the common part,
1443 val diff_two_say_set_eff
: 'a list
-> 'a list
->
1444 'a list
* 'a list
* 'a list
1446 (*****************************************************************************)
1447 (* Set as normal list *)
1448 (*****************************************************************************)
1452 (*****************************************************************************)
1453 (* Set as sorted list *)
1454 (*****************************************************************************)
1457 (*****************************************************************************)
1458 (* Sets specialized *)
1459 (*****************************************************************************)
1462 module StringSet = Set.Make(struct type t = string let compare = compare end)
1466 (*****************************************************************************)
1467 (* Assoc. But have a look too at Mapb.mli; it's better. Or use Hashtbl. *)
1468 (*****************************************************************************)
1470 type ('a
, '
b) assoc
= ('a
* '
b) list
1472 val assoc_to_function
: (* Eq a *) ('a
, '
b) assoc
-> ('a
-> '
b)
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
1480 val assoc
: 'a
-> ('a
* '
b) list
-> '
b
1482 val keys
: ('a
* '
b) list
-> 'a list
1483 val lookup
: 'a
-> ('a
* '
b) list
-> '
b
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
1489 val big_union_assoc
: ('a
-> '
b set
) -> 'a list
-> '
b set
1491 val assoc_reverse
: ('a
* '
b) list
-> ('
b * 'a
) list
1492 val assoc_map
: ('a
* '
b) list
-> ('a
* '
b) list
-> ('a
* 'a
) list
1494 val lookup_list
: 'a
-> ('a
, '
b) assoc list
-> '
b
1495 val lookup_list2
: 'a
-> ('a
, '
b) assoc list
-> '
b * int
1497 val assoc_option
: 'a
-> ('a
, '
b) assoc
-> '
b option
1498 val assoc_with_err_msg
: 'a
-> ('a
, '
b) assoc
-> '
b
1500 val sort_by_val_lowfirst
: ('a
,'
b) assoc
-> ('a
* '
b) list
1501 val sort_by_val_highfirst
: ('a
,'
b) assoc
-> ('a
* '
b) list
1503 val sort_by_key_lowfirst
: (int,'
b) assoc
-> (int * '
b) list
1504 val sort_by_key_highfirst
: (int,'
b) assoc
-> (int * '
b) list
1506 val sortgen_by_key_lowfirst
: ('a
,'
b) assoc
-> ('a
* '
b) list
1507 val sortgen_by_key_highfirst
: ('a
,'
b) assoc
-> ('a
* '
b) list
1509 (*****************************************************************************)
1510 (* Assoc, specialized. *)
1511 (*****************************************************************************)
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
1530 val intmap_to_list
: 'a
IntMap.t
-> (IntMap.key
* 'a
) list
1531 val intmap_string_of_t
: 'a
-> '
b -> string
1535 type key
= int * int
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
1550 val intintmap_to_list
: 'a
IntIntMap.t
-> (IntIntMap.key
* 'a
) list
1551 val intintmap_string_of_t
: 'a
-> '
b -> string
1554 (*****************************************************************************)
1556 (*****************************************************************************)
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
1562 * Note that Hashtbl module use different convention :( the object is
1563 * the first argument, not last as for List or Map.
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
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
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
1587 val hkeys
: ('a
, '
b) Hashtbl.t
-> 'a list
1589 (*****************************************************************************)
1591 (*****************************************************************************)
1593 type 'a hashset
= ('a
, bool) Hashtbl.t
1596 (* common use of hashset, in a hash of hash *)
1597 val hash_hashset_add
: 'a
-> '
b -> ('a
, '
b hashset
) Hashtbl.t
-> unit
1599 val hashset_to_set
:
1600 < fromlist
: ('a
) list
-> 'c
; .. > -> ('a
, '
b) Hashtbl.t
-> 'c
1602 val hashset_to_list
: 'a hashset
-> 'a list
1603 val hashset_of_list
: 'a list
-> 'a hashset
1606 (*****************************************************************************)
1608 (*****************************************************************************)
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
1616 val top_option
: 'a stack
-> 'a
option
1618 val push2
: 'a
-> 'a stack
ref -> unit
1619 val pop2
: 'a stack
ref -> 'a
1621 (*****************************************************************************)
1622 (* Stack with undo/redo support *)
1623 (*****************************************************************************)
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
1633 val top_undo_option
: 'a undo_stack
-> 'a
option
1636 (*****************************************************************************)
1638 (*****************************************************************************)
1639 type 'a bintree
= Leaf
of 'a
| Branch
of ('a bintree
* 'a bintree
)
1641 (*****************************************************************************)
1643 (*****************************************************************************)
1645 (* no empty tree, must have one root at least *)
1646 type 'a tree
= Tree
of 'a
* ('a tree
) list
1648 val tree_iter
: ('a
-> unit) -> 'a tree
-> unit
1651 (*****************************************************************************)
1652 (* N-ary tree with updatable childrens *)
1653 (*****************************************************************************)
1655 (* no empty tree, must have one root at least *)
1657 | NodeRef
of 'a
* 'a treeref list
ref
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) ->
1666 (('a
* 'a treeref list
ref) -> bool) ->
1667 'a treeref
-> 'a treeref
1669 val treeref_children_ref
:
1670 'a treeref
-> 'a treeref list
ref
1672 val find_treeref_with_parents_some
:
1673 ('a
* 'a treeref list
ref -> 'a list
-> 'c
option) ->
1676 val find_multi_treeref_with_parents_some
:
1677 ('a
* 'a treeref list
ref -> 'a list
-> 'c
option) ->
1678 'a treeref
-> 'c list
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.
1684 type ('a
, '
b) treeref2
=
1685 | NodeRef2
of 'a
* ('a
, '
b) treeref2 list
ref
1690 (('a
* ('a
, '
b) treeref2 list
ref) -> bool) ->
1691 ('a
, '
b) treeref2
-> ('a
, '
b) treeref2
1693 val treeref_node_iter_with_parents2
:
1694 (('a
* ('a
, '
b) treeref2 list
ref) -> ('a list
) -> unit) ->
1695 ('a
, '
b) treeref2
-> unit
1697 val treeref_node_iter2
:
1698 (('a
* ('a
, '
b) treeref2 list
ref) -> unit) -> ('a
, '
b) treeref2
-> unit
1703 val treeref_children_ref: ('a, 'b) treeref -> ('a, 'b) treeref list ref
1705 val find_treeref_with_parents_some:
1706 ('a * ('a, 'b) treeref list ref -> 'a list -> 'c option) ->
1707 ('a, 'b) treeref -> 'c
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
1714 (*****************************************************************************)
1715 (* Graph. But have a look too at Ograph_*.mli; it's better *)
1716 (*****************************************************************************)
1718 type 'a graph
= 'a set
* ('a
* 'a
) set
1720 val add_node
: 'a
-> 'a graph
-> 'a graph
1721 val del_node
: 'a
-> 'a graph
-> 'a graph
1723 val add_arc
: 'a
* 'a
-> 'a graph
-> 'a graph
1724 val del_arc
: 'a
* 'a
-> 'a graph
-> 'a graph
1726 val successors
: 'a
-> 'a graph
-> 'a set
1727 val predecessors
: 'a
-> 'a graph
-> 'a set
1729 val nodes
: 'a graph
-> 'a set
1731 val fold_upward
: ('a
-> '
b -> 'a
) -> '
b set
-> 'a
-> '
b graph
-> 'a
1733 val empty_graph
: 'a list
* '
b list
1736 (*****************************************************************************)
1738 (*****************************************************************************)
1740 (* mostly alias to functions in List *)
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
1746 val member
: 'a
-> 'a list
-> bool
1748 val iter
: ('a
-> unit) -> 'a list
-> unit
1750 val find
: ('a
-> bool) -> 'a list
-> 'a
1752 val exists
: ('a
-> bool) -> 'a list
-> bool
1753 val forall
: ('a
-> bool) -> 'a list
-> bool
1755 val big_union
: ('a
-> '
b set
) -> 'a list
-> '
b set
1757 (* same than [] but easier to search for, because [] can also be a pattern *)
1758 val empty_list
: 'a list
1760 val sort
: ('a
-> 'a
-> int) -> 'a list
-> 'a list
1762 val length
: 'a list
-> int
1764 val null
: 'a list
-> bool
1766 val head
: 'a list
-> 'a
1767 val tail
: 'a list
-> 'a list
1769 val is_singleton
: 'a list
-> bool
1779 (*###########################################################################*)
1780 (* And now misc functions *)
1781 (*###########################################################################*)
1783 (*****************************************************************************)
1785 (*****************************************************************************)
1787 (* cf oassocbdb.ml or oassocdbm.ml *)
1789 (*****************************************************************************)
1790 (* GUI (LFS, CComment, otimetracker) *)
1791 (*****************************************************************************)
1793 (* cf ocamlgtk and my gui.ml *)
1796 (*****************************************************************************)
1797 (* Graphics (otimetracker) *)
1798 (*****************************************************************************)
1800 (* cf ocamlgl and my opengl.ml *)
1804 (*****************************************************************************)
1805 (* Geometry (ICFP raytracer) *)
1806 (*****************************************************************************)
1808 type vector
= float * float * float
1813 val dotproduct
: vector
* vector
-> float
1815 val vector_length
: vector
-> float
1817 val minus_point
: point
* point
-> vector
1819 val distance
: point
* point
-> float
1821 val normalise
: vector
-> vector
1823 val mult_coeff
: vector
-> float -> vector
1825 val add_vector
: vector
-> vector
-> vector
1826 val mult_vector
: vector
-> vector
-> vector
1827 val sum_vector
: vector list
-> vector
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
1837 (*****************************************************************************)
1839 (*****************************************************************************)
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
1845 (*****************************************************************************)
1846 (* Parsers (aop-colcombet) *)
1847 (*****************************************************************************)
1849 val parserCommon
: Lexing.lexbuf
-> ('a
-> Lexing.lexbuf
-> '
b) -> 'a
-> '
b
1850 val getDoubleParser
:
1851 ('a
-> Lexing.lexbuf
-> '
b) -> 'a
-> (string -> '
b) * (string -> '
b)
1853 (*****************************************************************************)
1854 (* Parsers (cocci) *)
1855 (*****************************************************************************)
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:
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
1866 * Hence those functions to overcome the previous limitation.
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
1881 (* array[i] will contain the (line x col) of the i char position *)
1882 val full_charpos_to_pos
: filename
-> (int * int) array
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
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.
1893 val info_from_charpos
: int -> filename
-> (int * int * string)
1895 val error_message
: filename
-> (string * int) -> string
1896 val error_message_short
: filename
-> (string * int) -> string
1898 (* add a 'decalage/shift' argument to handle stuff such as cpp which includes
1899 * files and who can make shift.
1901 val error_messagebis
: filename
-> (string * int) -> int -> string
1903 (*****************************************************************************)
1904 (* Scope managment (cocci) *)
1905 (*****************************************************************************)
1907 (* for example of use, see the code used in coccinelle *)
1908 type ('a
, '
b) scoped_env
= ('a
, '
b) assoc list
1910 val lookup_env
: (* Eq a *) 'a
-> ('a
, '
b) scoped_env
-> '
b
1911 val member_env_key
: 'a
-> ('a
, '
b) scoped_env
-> bool
1913 val new_scope
: ('a
, '
b) scoped_env
ref -> unit
1914 val del_scope
: ('a
, '
b) scoped_env
ref -> unit
1916 val do_in_new_scope
: ('a
, '
b) scoped_env
ref -> (unit -> unit) -> unit
1918 val add_in_scope
: ('a
, '
b) scoped_env
ref -> 'a
* '
b -> unit
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
;
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
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
1934 val new_scope_h
: ('a
, '
b) scoped_h_env
ref -> unit
1935 val del_scope_h
: ('a
, '
b) scoped_h_env
ref -> unit
1937 val do_in_new_scope_h
: ('a
, '
b) scoped_h_env
ref -> (unit -> unit) -> unit
1939 val add_in_scope_h
: ('a
, '
b) scoped_h_env
ref -> 'a
* '
b -> unit
1941 (*****************************************************************************)
1942 (* Terminal (LFS) *)
1943 (*****************************************************************************)
1945 (* don't forget to call Common_extra.set_link () *)
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
1952 (*****************************************************************************)
1953 (* Flags and actions *)
1954 (*****************************************************************************)
1956 val cmdline_flags_devel
: unit -> cmdline_options
1957 val cmdline_flags_verbose
: unit -> cmdline_options
1958 val cmdline_flags_other
: unit -> cmdline_options
1960 (*****************************************************************************)
1962 (*****************************************************************************)
1964 val generic_print
: 'a
-> string -> string
1970 method fold
: ('
b -> 'a
-> '
b) -> '
b -> '
b
1971 method view
: 'a list
1974 val typing_sux_test
: unit -> unit