Module Lib
General-purpose library functions
- author
- Christoph Sticksel
Helper functions
Option types
Integer functions
Integer functions
List functions
val (@::) : 'a option -> 'a list -> 'a listAdd element to the head of the list if the option value is not
None.The function symbol is right-associative and infix:
Some 1 @:: None @:: Some 2 @:: [3;4]returns
\[1;2;3;4\]
val list_index : ('a -> bool) -> 'a list -> intReturn the index of the first element that satisfies the predicate
p, raise excpetionNot_foundif no element satisfies the predicate.
val list_indexes : 'a list -> 'a list -> int listlist_indexes l1 l2returns the indexes in listl2of elements in listl1
val list_filter_nth : 'a list -> int list -> 'a listlist_filter_nth l [p1; p2; ...]returns the elementslat positionsp1,p2etc.
val chain_list_p : 'a list -> ('a * 'a) listchain_list_p [e1; e2; ...]is[(e1, e2); (e2, e3); ... ]
val list_subtract : 'a list -> 'a list -> 'a listReturn a list containing all values in the first list that are not in the second list
val list_merge_uniq : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a listMerge two sorted lists without physical duplicates to a sorted list without physical duplicates
val list_inter_uniq : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a listFrom two sorted lists without physical duplicates return a sorted list without physical duplicates containing elements in both lists
val list_diff_uniq : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a listFrom two sorted lists without physical duplicates return a sorted list without physical duplicates containing elements in the first but not in the second list
val list_subset_uniq : ('a -> 'a -> int) -> 'a list -> 'a list -> boolFor two sorted lists without physical duplicates return true if the first list contains a physically equal element for each element in the second list
val list_join : ('a -> 'a -> bool) -> ('a * 'b) list -> ('a * 'b list) list -> ('a * 'b list) listGiven two ordered association lists with identical keys, push the values of each element of the first association list to the list of elements of the second association list.
The returned association list is in the order of the input lists, the function
equalis used to compare keys. RaiseFailure "list_join"if the lists are not of identical length and the keys at each element are equal.
Array functions
Set functions
module IntegerSet : Stdlib.Set.S with type IntegerSet.elt = intSets of integers
module IntegerHashtbl : Stdlib.Hashtbl.S with type IntegerHashtbl.key = intHashtable of integers
Pretty-printing helpers
val pp_print_arrayi : (Stdlib.Format.formatter -> int -> 'a -> unit) -> (unit, Stdlib.Format.formatter, unit) Stdlib.format -> Stdlib.Format.formatter -> 'a array -> unitPretty-print an array with given separator
pp_print_array elem_printer separator formatter arraycalls, for each indexiof the array whose corresponding element iselement,elem_printer formatter i element. Between each of these calls it prints the stringseparator.In order to get line breaks between the elements, do not use a line feed character
\nas separator, this might mess up indentation. Instead wrap the list into a vertical box with the format string@[<v>%a@]and the empty string as separator.
val pp_print_list : (Stdlib.Format.formatter -> 'a -> unit) -> ('b, Stdlib.Format.formatter, unit) Stdlib.format -> Stdlib.Format.formatter -> 'a list -> unitPretty-print a list with given separator
pp_print_list p s f lpretty-prints the elements in the listlby calling the pretty-printerpon each, separating the elements by printing the strings.In order to get line breaks between the elements, do not use a line feed character
\nas separator, this might mess up indentation. Instead wrap the list into a vertical box with the format string@[<v>%a@]and the empty string as separator.
val pp_print_listi : (Stdlib.Format.formatter -> int -> 'a -> unit) -> ('b, Stdlib.Format.formatter, unit) Stdlib.format -> Stdlib.Format.formatter -> 'a list -> unitPretty-print a list with given separator and maintain a counter of elements
See
pp_print_list, except that the pretty-printer is passes an zero-based counter for the list's elements as the argument preceding the list element.
val pp_print_list2i : (Stdlib.Format.formatter -> int -> 'a -> 'b -> unit) -> ('c, Stdlib.Format.formatter, unit) Stdlib.format -> Stdlib.Format.formatter -> 'a list -> 'b list -> unitPretty-print two lists of the same length with given separator and maintain a counter of their elements.
val pp_print_option : (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a option -> unitPretty-print an option type
val pp_print_if_not_empty : (unit, Stdlib.Format.formatter, unit) Stdlib.format -> Stdlib.Format.formatter -> 'a list -> unitPretty-print if list is not empty
val width_of_string : string -> intReturn the width of the string, meaning the wisth of it's longest line
Logging
type log_level=|L_off|L_fatal|L_error|L_warn|L_note|L_info|L_debug|L_traceLevels of log messages
L_fatalA severe error that will lead to an immediate abort
L_errorAn error event that might still allow to continue
L_warnA potentially harmful situation
L_noteAn important note (soft warning)
L_infoAn informational message that highlight progress at a coarse-grained level
L_debugA fine-grained informational event that is useful for debugging but not for an end user
L_traceA finer-grained informational event thanL_debug
val default_log_level : log_levelDefault log level.
val int_of_log_level : log_level -> intAssociate an integer with each level to induce a total ordering
val log_level_of_int : int -> log_levelval string_of_log_level : log_level -> stringval log_ppf : Stdlib.Format.formatter Stdlib.refCurrent formatter for output
val set_log_level : log_level -> unitSet log level
Only output messages of levels with equal or higher priority
val get_log_level : unit -> log_levelGets the log level.
val output_on_level : log_level -> boolReturn true if given log level is of higher or equal priority than current log level?
val ignore_or_fprintf : log_level -> Stdlib.Format.formatter -> ('a, Stdlib.Format.formatter, unit) Stdlib.format -> 'aReturn Format.fprintf if level is is of higher or equal priority than current log level, otherwise return Format.ifprintf
System functions
type kind_module=[|`IC3|`BMC|`IND|`IND2|`INVGEN|`INVGENOS|`INVGENINT|`INVGENINTOS|`INVGENREAL|`INVGENREALOS|`C2I|`Interpreter|`Supervisor|`Parser|`Certif|`MCS]Kind modules
val pp_print_process_status : Stdlib.Format.formatter -> Unix.process_status -> unitPretty-print the termination status of a process
val pp_print_kind_module : Stdlib.Format.formatter -> kind_module -> unitPretty-print the name of a kind module
val string_of_kind_module : kind_module -> stringString representation of a process type
val int_of_kind_module : kind_module -> intString representation of a process type
val short_name_of_kind_module : kind_module -> stringReturn a short representation of kind module
val kind_module_of_string : string -> kind_moduleKind module of a string
Positions in the input
val dummy_pos : positionDummy position different from any valid position
val is_dummy_pos : position -> boolReturn
trueif the position is not a valid position in the input
val pp_print_position : Stdlib.Format.formatter -> position -> unitPretty-print a position
val pp_print_pos : Stdlib.Format.formatter -> position -> unitPretty-print a position in a concise way
val file_row_col_of_pos : position -> string * int * intReturn the file, line and column of a position; fail with
Invalid_argument "file_row_col_of_pos"if the position is a dummy position
val pos_of_file_row_col : (string * int * int) -> positionInverse of
file_row_col_of_pos
val position_of_lexing : Stdlib.Lexing.position -> positionConvert a position of the lexer to a position
val print_backtrace : Stdlib.Format.formatter -> Stdlib.Printexc.raw_backtrace -> unitPretty print a backtrace
val files_cat_open : ?add_prefix:(Stdlib.Format.formatter -> unit) -> string list -> string -> Unix.file_descrval syscall : string -> stringGet standard output of command
val reset_gc_params : unit -> unitReset the parameters of the GC to its default values. Call after
set_liberal_gc.
module Paths : sig ... endPaths Kind 2 can write some files. Factored to avoid clashes.
module ReservedIds : sig ... endReserved identifiers.
module ExitCodes : sig ... endExit codes.
module Names : sig ... endFile names.