Adding comments 2

This commit is contained in:
nathan moreau 2018-01-21 17:09:42 +01:00
parent b04e097cf4
commit 25f919070f
10 changed files with 87 additions and 131 deletions

View file

@ -134,7 +134,7 @@ val lookup_exn : cmp:'a ord -> key:'a -> 'a t -> int
val bsearch : cmp:('a -> 'a -> int) -> key:'a -> 'a t -> val bsearch : cmp:('a -> 'a -> int) -> key:'a -> 'a t ->
[ `All_lower | `All_bigger | `Just_after of int | `Empty | `At of int ] [ `All_lower | `All_bigger | `Just_after of int | `Empty | `At of int ]
(** [bsearch ?cmp x arr] finds the index of the object [x] in the array [arr], (** [bsearch ?cmp key arr] finds the index of the object [key] in the array [arr],
provided [arr] is {b sorted} using [cmp]. If the array is not sorted, provided [arr] is {b sorted} using [cmp]. If the array is not sorted,
the result is not specified (may raise Invalid_argument). the result is not specified (may raise Invalid_argument).
@ -145,7 +145,7 @@ val bsearch : cmp:('a -> 'a -> int) -> key:'a -> 'a t ->
- [`At i] if [cmp arr.(i) key = 0] (for some i) - [`At i] if [cmp arr.(i) key = 0] (for some i)
- [`All_lower] if all elements of [arr] are lower than [key] - [`All_lower] if all elements of [arr] are lower than [key]
- [`All_bigger] if all elements of [arr] are bigger than [key] - [`All_bigger] if all elements of [arr] are bigger than [key]
- [`Just_after i] if [arr.(i) < x < arr.(i+1)] - [`Just_after i] if [arr.(i) < key < arr.(i+1)]
- [`Empty] if the array is empty. - [`Empty] if the array is empty.
@raise Invalid_argument if the array is found to be unsorted w.r.t [cmp]. @raise Invalid_argument if the array is found to be unsorted w.r.t [cmp].

View file

@ -1,7 +1,7 @@
(* This file is free software, part of containers. See file "license" for more details. *) (* This file is free software, part of containers. See file "license" for more details. *)
(** {1 complements to list} *) (** {1 Complements to list} *)
(*$inject (*$inject
let lsort l = List.sort Pervasives.compare l let lsort l = List.sort Pervasives.compare l

View file

@ -1,7 +1,7 @@
(* This file is free software, part of containers. See file "license" for more details. *) (* This file is free software, part of containers. See file "license" for more details. *)
(** {1 complements to list} *) (** {1 Complements to list} *)
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit
type 'a gen = unit -> 'a option type 'a gen = unit -> 'a option

View file

@ -1,7 +1,7 @@
(* This file is free software, part of containers. See file "license" for more details. *) (* This file is free software, part of containers. See file "license" for more details. *)
(** {1 complements to list} *) (** {1 Complements to list} *)
include module type of ListLabels include module type of ListLabels

View file

@ -35,28 +35,28 @@ val cycle : 'a t -> 'a t
val unfold : ('b -> ('a * 'b) option) -> 'b -> 'a t val unfold : ('b -> ('a * 'b) option) -> 'b -> 'a t
(** [unfold f acc] calls [f acc] and: (** [unfold f acc] calls [f acc] and:
- if [f acc = Some (x, acc')], yield [x], continue with [unfold f acc'] - if [f acc = Some (x, acc')], yield [x], continue with [unfold f acc'].
- if [f acc = None], stops - if [f acc = None], stops.
@since 0.13 *) @since 0.13 *)
val is_empty : 'a t -> bool val is_empty : 'a t -> bool
val head : 'a t -> 'a option val head : 'a t -> 'a option
(** Head of the list (** Head of the list.
@since 0.13 *) @since 0.13 *)
val head_exn : 'a t -> 'a val head_exn : 'a t -> 'a
(** Unsafe version of {!head} (** Unsafe version of {!head}.
@raise Not_found if the list is empty @raise Not_found if the list is empty.
@since 0.13 *) @since 0.13 *)
val tail : 'a t -> 'a t option val tail : 'a t -> 'a t option
(** Tail of the list (** Tail of the list.
@since 0.13 *) @since 0.13 *)
val tail_exn : 'a t -> 'a t val tail_exn : 'a t -> 'a t
(** Unsafe version of {!tail} (** Unsafe version of {!tail}.
@raise Not_found if the list is empty @raise Not_found if the list is empty.
@since 0.13 *) @since 0.13 *)
val equal : 'a equal -> 'a t equal val equal : 'a equal -> 'a t equal
@ -66,12 +66,12 @@ val compare : 'a ord -> 'a t ord
(** Lexicographic comparison. Eager. *) (** Lexicographic comparison. Eager. *)
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
(** Fold on values *) (** Fold on values. *)
val iter : ('a -> unit) -> 'a t -> unit val iter : ('a -> unit) -> 'a t -> unit
val iteri : (int -> 'a -> unit) -> 'a t -> unit val iteri : (int -> 'a -> unit) -> 'a t -> unit
(** Iterate with index (starts at 0) (** Iterate with index (starts at 0).
@since 0.13 *) @since 0.13 *)
val length : _ t -> int val length : _ t -> int
@ -90,7 +90,7 @@ val drop_while : ('a -> bool) -> 'a t -> 'a t
val map : ('a -> 'b) -> 'a t -> 'b t val map : ('a -> 'b) -> 'a t -> 'b t
val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t
(** Map with index (starts at 0) (** Map with index (starts at 0).
@since 0.13 *) @since 0.13 *)
val fmap : ('a -> 'b option) -> 'a t -> 'b t val fmap : ('a -> 'b option) -> 'a t -> 'b t
@ -101,17 +101,17 @@ val append : 'a t -> 'a t -> 'a t
val product_with : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t val product_with : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
(** Fair product of two (possibly infinite) lists into a new list. Lazy. (** Fair product of two (possibly infinite) lists into a new list. Lazy.
The first parameter is used to combine each pair of elements The first parameter is used to combine each pair of elements.
@since 0.3.3 *) @since 0.3.3 *)
val product : 'a t -> 'b t -> ('a * 'b) t val product : 'a t -> 'b t -> ('a * 'b) t
(** Specialization of {!product_with} producing tuples (** Specialization of {!product_with} producing tuples.
@since 0.3.3 *) @since 0.3.3 *)
val group : 'a equal -> 'a t -> 'a t t val group : 'a equal -> 'a t -> 'a t t
(** [group eq l] groups together consecutive elements that satisfy [eq]. Lazy. (** [group eq l] groups together consecutive elements that satisfy [eq]. Lazy.
For instance [group (=) [1;1;1;2;2;3;3;1]] yields For instance [group (=) [1;1;1;2;2;3;3;1]] yields
[[1;1;1]; [2;2]; [3;3]; [1]] [[1;1;1]; [2;2]; [3;3]; [1]].
@since 0.3.3 *) @since 0.3.3 *)
val uniq : 'a equal -> 'a t -> 'a t val uniq : 'a equal -> 'a t -> 'a t
@ -130,7 +130,7 @@ val range : int -> int -> int t
val (--) : int -> int -> int t val (--) : int -> int -> int t
(** [a -- b] is the range of integers containing (** [a -- b] is the range of integers containing
[a] and [b] (therefore, never empty) *) [a] and [b] (therefore, never empty). *)
val (--^) : int -> int -> int t val (--^) : int -> int -> int t
(** [a -- b] is the integer range from [a] to [b], where [b] is excluded. (** [a -- b] is the integer range from [a] to [b], where [b] is excluded.
@ -139,43 +139,43 @@ val (--^) : int -> int -> int t
(** {2 Operations on two Collections} *) (** {2 Operations on two Collections} *)
val fold2 : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> 'a t -> 'b t -> 'acc val fold2 : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> 'a t -> 'b t -> 'acc
(** Fold on two collections at once. Stop at soon as one of them ends *) (** Fold on two collections at once. Stop at soon as one of them ends. *)
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
(** Map on two collections at once. Stop as soon as one of the (** Map on two collections at once. Stop as soon as one of the
arguments is exhausted *) arguments is exhausted. *)
val iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unit val iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unit
(** Iterate on two collections at once. Stop as soon as one of them ends *) (** Iterate on two collections at once. Stop as soon as one of them ends. *)
val for_all2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool val for_all2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
val exists2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool val exists2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
val merge : 'a ord -> 'a t -> 'a t -> 'a t val merge : 'a ord -> 'a t -> 'a t -> 'a t
(** Merge two sorted iterators into a sorted iterator *) (** Merge two sorted iterators into a sorted iterator. *)
val zip : 'a t -> 'b t -> ('a * 'b) t val zip : 'a t -> 'b t -> ('a * 'b) t
(** Combine elements pairwise. Stops as soon as one of the lists stops. (** Combine elements pairwise. Stops as soon as one of the lists stops.
@since 0.13 *) @since 0.13 *)
val unzip : ('a * 'b) t -> 'a t * 'b t val unzip : ('a * 'b) t -> 'a t * 'b t
(** Splits each tuple in the list (** Splits each tuple in the list.
@since 0.13 *) @since 0.13 *)
(** {2 Misc} *) (** {2 Misc} *)
val sort : cmp:'a ord -> 'a t -> 'a t val sort : cmp:'a ord -> 'a t -> 'a t
(** Eager sort. Requires the iterator to be finite. O(n ln(n)) time (** Eager sort. Requires the iterator to be finite. [O(n ln(n))] time
and space. and space.
@since 0.3.3 *) @since 0.3.3 *)
val sort_uniq : cmp:'a ord -> 'a t -> 'a t val sort_uniq : cmp:'a ord -> 'a t -> 'a t
(** Eager sort that removes duplicate values. Requires the iterator to be (** Eager sort that removes duplicate values. Requires the iterator to be
finite. O(n ln(n)) time and space. finite. [O(n ln(n))] time and space.
@since 0.3.3 *) @since 0.3.3 *)
val memoize : 'a t -> 'a t val memoize : 'a t -> 'a t
(** Avoid recomputations by caching intermediate results (** Avoid recomputations by caching intermediate results.
@since 0.14 *) @since 0.14 *)
(** {2 Fair Combinations} *) (** {2 Fair Combinations} *)
@ -189,7 +189,7 @@ val fair_flat_map : ('a -> 'b t) -> 'a t -> 'b t
@since 0.13 *) @since 0.13 *)
val fair_app : ('a -> 'b) t -> 'a t -> 'b t val fair_app : ('a -> 'b) t -> 'a t -> 'b t
(** Fair version of {!(<*>)} (** Fair version of {!(<*>)}.
@since 0.13 *) @since 0.13 *)
(** {2 Implementations} (** {2 Implementations}
@ -202,11 +202,11 @@ val (>|=) : 'a t -> ('a -> 'b) -> 'b t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val (>>-) : 'a t -> ('a -> 'b t) -> 'b t val (>>-) : 'a t -> ('a -> 'b t) -> 'b t
(** Infix version of {! fair_flat_map} (** Infix version of {! fair_flat_map}.
@since 0.13 *) @since 0.13 *)
val (<.>) : ('a -> 'b) t -> 'a t -> 'b t val (<.>) : ('a -> 'b) t -> 'a t -> 'b t
(** Infix version of {!fair_app} (** Infix version of {!fair_app}.
@since 0.13 *) @since 0.13 *)
(** {2 Infix operators} (** {2 Infix operators}
@ -246,7 +246,7 @@ val to_list : 'a t -> 'a list
(** Gather all values into a list *) (** Gather all values into a list *)
val of_array : 'a array -> 'a t val of_array : 'a array -> 'a t
(** Iterate on the array (** Iterate on the array.
@since 0.13 *) @since 0.13 *)
val to_array : 'a t -> 'a array val to_array : 'a t -> 'a array
@ -254,18 +254,18 @@ val to_array : 'a t -> 'a array
@since 0.13 *) @since 0.13 *)
val to_rev_list : 'a t -> 'a list val to_rev_list : 'a t -> 'a list
(** Convert to a list, in reverse order. More efficient than {!to_list} *) (** Convert to a list, in reverse order. More efficient than {!to_list}. *)
val to_seq : 'a t -> 'a sequence val to_seq : 'a t -> 'a sequence
val to_gen : 'a t -> 'a gen val to_gen : 'a t -> 'a gen
val of_gen : 'a gen -> 'a t val of_gen : 'a gen -> 'a t
(** [of_gen g] consumes the generator and caches intermediate results (** [of_gen g] consumes the generator and caches intermediate results.
@since 0.13 *) @since 0.13 *)
(** {2 IO} *) (** {2 IO} *)
val pp : ?sep:string -> 'a printer -> 'a t printer val pp : ?sep:string -> 'a printer -> 'a t printer
(** Print the list with the given separator (default ","). (** Print the list with the given separator (default ",").
Does not print opening/closing delimiters *) Does not print opening/closing delimiters. *)

View file

@ -1,27 +1,4 @@
(* (* This file is free software, part of containers. See file "license" for more details. *)
copyright (c) 2013-2014, simon cruanes
all rights reserved.
redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. redistributions in binary
form must reproduce the above copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other materials provided with
the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)
(** {1 Lazy Tree Structure} (** {1 Lazy Tree Structure}
This structure can be used to represent trees and directed This structure can be used to represent trees and directed

View file

@ -1,27 +1,4 @@
(* (* This file is free software, part of containers. See file "license" for more details. *)
copyright (c) 2013-2014, simon cruanes
all rights reserved.
redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. redistributions in binary
form must reproduce the above copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other materials provided with
the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)
(** {1 Lazy Tree Structure} (** {1 Lazy Tree Structure}
This structure can be used to represent trees and directed This structure can be used to represent trees and directed
@ -42,16 +19,16 @@ val empty : 'a t
val is_empty : _ t -> bool val is_empty : _ t -> bool
val singleton : 'a -> 'a t val singleton : 'a -> 'a t
(** Tree with only one label *) (** Tree with only one label. *)
val node : 'a -> 'a t list -> 'a t val node : 'a -> 'a t list -> 'a t
(** Build a node from a label and a list of children *) (** Build a node from a label and a list of children. *)
val node1 : 'a -> 'a t -> 'a t val node1 : 'a -> 'a t -> 'a t
(** Node with one child *) (** Node with one child. *)
val node2 : 'a -> 'a t -> 'a t -> 'a t val node2 : 'a -> 'a t -> 'a t -> 'a t
(** Node with two children *) (** Node with two children. *)
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
(** Fold on values in no specified order. May not terminate if the (** Fold on values in no specified order. May not terminate if the
@ -60,10 +37,10 @@ val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
val iter : ('a -> unit) -> 'a t -> unit val iter : ('a -> unit) -> 'a t -> unit
val size : _ t -> int val size : _ t -> int
(** Number of elements *) (** Number of elements. *)
val height : _ t -> int val height : _ t -> int
(** Length of the longest path to empty leaves *) (** Length of the longest path to empty leaves. *)
val map : ('a -> 'b) -> 'a t -> 'b t val map : ('a -> 'b) -> 'a t -> 'b t
@ -81,21 +58,21 @@ class type ['a] pset = object
end end
val set_of_cmp : cmp:('a -> 'a -> int) -> unit -> 'a pset val set_of_cmp : cmp:('a -> 'a -> int) -> unit -> 'a pset
(** Build a set structure given a total ordering *) (** Build a set structure given a total ordering. *)
val dfs : pset:'a pset -> 'a t -> [ `Enter of 'a | `Exit of 'a ] klist val dfs : pset:'a pset -> 'a t -> [ `Enter of 'a | `Exit of 'a ] klist
(** Depth-first traversal of the tree *) (** Depth-first traversal of the tree. *)
val bfs : pset:'a pset -> 'a t -> 'a klist val bfs : pset:'a pset -> 'a t -> 'a klist
(** Breadth-first traversal of the tree *) (** Breadth-first traversal of the tree. *)
val force : 'a t -> ([ `Nil | `Node of 'a * 'b list ] as 'b) val force : 'a t -> ([ `Nil | `Node of 'a * 'b list ] as 'b)
(** [force t] evaluates [t] completely and returns a regular tree (** [force t] evaluates [t] completely and returns a regular tree
structure structure.
@since 0.13 *) @since 0.13 *)
val find : pset:'a pset -> ('a -> 'b option) -> 'a t -> 'b option val find : pset:'a pset -> ('a -> 'b option) -> 'a t -> 'b option
(** Look for an element that maps to [Some _] *) (** Look for an element that maps to [Some _]. *)
(** {2 Pretty-printing} (** {2 Pretty-printing}
@ -137,13 +114,13 @@ module Dot : sig
] (** Dot attributes for nodes *) ] (** Dot attributes for nodes *)
type graph = (string * attribute list t list) type graph = (string * attribute list t list)
(** A dot graph is a name, plus a list of trees labelled with attributes *) (** A dot graph is a name, plus a list of trees labelled with attributes. *)
val mk_id : ('a, Buffer.t, unit, attribute) format4 -> 'a val mk_id : ('a, Buffer.t, unit, attribute) format4 -> 'a
(** Using a formatter string, build an ID *) (** Using a formatter string, build an ID. *)
val mk_label : ('a, Buffer.t, unit, attribute) format4 -> 'a val mk_label : ('a, Buffer.t, unit, attribute) format4 -> 'a
(** Using a formatter string, build a label *) (** Using a formatter string, build a label. *)
val make : name:string -> attribute list t list -> graph val make : name:string -> attribute list t list -> graph
@ -163,6 +140,6 @@ module Dot : sig
val to_file : ?name:string -> string -> attribute list t list -> unit val to_file : ?name:string -> string -> attribute list t list -> unit
(** [to_file filename trees] makes a graph out of the trees, opens the (** [to_file filename trees] makes a graph out of the trees, opens the
file [filename] and prints the graph into the file. file [filename] and prints the graph into the file.
@param name name of the graph @param name name of the graph.
@since 0.6.1 *) @since 0.6.1 *)
end end

View file

@ -11,25 +11,25 @@ and +'a node =
| Cons of 'a * 'a t | Cons of 'a * 'a t
val empty : 'a t val empty : 'a t
(** Empty list *) (** Empty list. *)
val return : 'a -> 'a t val return : 'a -> 'a t
(** Return a computed value *) (** Return a computed value. *)
val is_empty : _ t -> bool val is_empty : _ t -> bool
(** Evaluates the head *) (** Evaluates the head. *)
val length : _ t -> int val length : _ t -> int
(** [length l] returns the number of elements in [l], eagerly (linear time). (** [length l] returns the number of elements in [l], eagerly (linear time).
Caution, will not terminate if [l] is infinite *) Caution, will not terminate if [l] is infinite. *)
val cons : 'a -> 'a t -> 'a t val cons : 'a -> 'a t -> 'a t
val head : 'a t -> ('a * 'a t) option val head : 'a t -> ('a * 'a t) option
(** Evaluate head, return it, or [None] if the list is empty *) (** Evaluate head, return it, or [None] if the list is empty. *)
val map : f:('a -> 'b) -> 'a t -> 'b t val map : f:('a -> 'b) -> 'a t -> 'b t
(** Lazy map *) (** Lazy map. *)
val filter : f:('a -> bool) -> 'a t -> 'a t val filter : f:('a -> bool) -> 'a t -> 'a t
(** Filter values. (** Filter values.
@ -40,10 +40,10 @@ val take : int -> 'a t -> 'a t
@since 0.18 *) @since 0.18 *)
val append : 'a t -> 'a t -> 'a t val append : 'a t -> 'a t -> 'a t
(** Lazy concatenation *) (** Lazy concatenation. *)
val flat_map : f:('a -> 'b t) -> 'a t -> 'b t val flat_map : f:('a -> 'b t) -> 'a t -> 'b t
(** Monadic flatten + map *) (** Monadic flatten + map. *)
module Infix : sig module Infix : sig
val (>|=) : 'a t -> ('a -> 'b) -> 'b t val (>|=) : 'a t -> ('a -> 'b) -> 'b t

View file

@ -19,12 +19,14 @@ val equal : t -> t -> bool
val compare : t -> t -> int val compare : t -> t -> int
val hash : t -> int val hash : t -> int
val atom : string -> t (** Build an atom directly from a string *) val atom : string -> t
(** Build an atom directly from a string. *)
val of_int : int -> t val of_int : int -> t
val of_bool : bool -> t val of_bool : bool -> t
val of_list : t list -> t val of_list : t list -> t
val of_rev_list : t list -> t (** Reverse the list *) val of_rev_list : t list -> t
(** Reverse the list. *)
val of_float : float -> t val of_float : float -> t
val of_unit : t val of_unit : t
val of_pair : t * t -> t val of_pair : t * t -> t
@ -34,13 +36,13 @@ val of_quad : t * t * t * t -> t
val of_variant : string -> t list -> t val of_variant : string -> t list -> t
(** [of_variant name args] is used to encode algebraic variants (** [of_variant name args] is used to encode algebraic variants
into a S-expr. For instance [of_variant "some" [of_int 1]] into a S-expr. For instance [of_variant "some" [of_int 1]]
represents the value [Some 1] *) represents the value [Some 1]. *)
val of_field : string -> t -> t val of_field : string -> t -> t
(** Used to represent one record field *) (** Used to represent one record field. *)
val of_record : (string * t) list -> t val of_record : (string * t) list -> t
(** Represent a record by its named fields *) (** Represent a record by its named fields. *)
(** {2 Printing} *) (** {2 Printing} *)
@ -51,21 +53,21 @@ val to_string : t -> string
val to_file : string -> t -> unit val to_file : string -> t -> unit
val to_file_seq : string -> t sequence -> unit val to_file_seq : string -> t sequence -> unit
(** Print the given sequence of expressions to a file *) (** Print the given sequence of expressions to a file. *)
val to_chan : out_channel -> t -> unit val to_chan : out_channel -> t -> unit
val pp : Format.formatter -> t -> unit val pp : Format.formatter -> t -> unit
(** Pretty-printer nice on human eyes (including indentation) *) (** Pretty-printer nice on human eyes (including indentation). *)
val pp_noindent : Format.formatter -> t -> unit val pp_noindent : Format.formatter -> t -> unit
(** Raw, direct printing as compact as possible *) (** Raw, direct printing as compact as possible. *)
(** {2 Parsing} *) (** {2 Parsing} *)
(** A parser of ['a] can return [Yield x] when it parsed a value, (** A parser of ['a] can return [Yield x] when it parsed a value,
or [Fail e] when a parse error was encountered, or or [Fail e] when a parse error was encountered, or
[End] if the input was empty *) [End] if the input was empty. *)
type 'a parse_result = type 'a parse_result =
| Yield of 'a | Yield of 'a
| Fail of string | Fail of string
@ -79,24 +81,24 @@ module Decoder : sig
val next : t -> sexp parse_result val next : t -> sexp parse_result
(** Parse the next S-expression or return an error if the input isn't (** Parse the next S-expression or return an error if the input isn't
long enough or isn't a proper S-expression *) long enough or isn't a proper S-expression. *)
end end
val parse_string : string -> t or_error val parse_string : string -> t or_error
(** Parse a string *) (** Parse a string. *)
val parse_chan : in_channel -> t or_error val parse_chan : in_channel -> t or_error
(** Parse a S-expression from the given channel. Can read more data than (** Parse a S-expression from the given channel. Can read more data than
necessary, so don't use this if you need finer-grained control (e.g. necessary, so don't use this if you need finer-grained control (e.g.
to read something else {b after} the S-exp) *) to read something else {b after} the S-exp). *)
val parse_chan_gen : in_channel -> t or_error gen val parse_chan_gen : in_channel -> t or_error gen
(** Parse a channel into a generator of S-expressions *) (** Parse a channel into a generator of S-expressions. *)
val parse_chan_list : in_channel -> t list or_error val parse_chan_list : in_channel -> t list or_error
val parse_file : string -> t or_error val parse_file : string -> t or_error
(** Open the file and read a S-exp from it *) (** Open the file and read a S-exp from it. *)
val parse_file_list : string -> t list or_error val parse_file_list : string -> t list or_error
(** Open the file and read a S-exp from it *) (** Open the file and read a S-exp from it. *)

View file

@ -40,8 +40,8 @@ val call_full :
returning. returning.
@param stdin if provided, the generator or string is consumed and fed to @param stdin if provided, the generator or string is consumed and fed to
the subprocess input channel, which is then closed. the subprocess input channel, which is then closed.
@param bufsize buffer size used to read stdout and stderr @param bufsize buffer size used to read stdout and stderr.
@param env environment to run the command in @param env environment to run the command in.
*) *)
(*$T (*$T
@ -94,7 +94,7 @@ val async_call : ?env:string array ->
'a 'a
(** Spawns a subprocess, like {!call}, but the subprocess's channels are (** Spawns a subprocess, like {!call}, but the subprocess's channels are
line generators and line sinks (for stdin). line generators and line sinks (for stdin).
if [p] is [async_call "cmd"], then [p#wait] waits for the subprocess If [p] is [async_call "cmd"], then [p#wait] waits for the subprocess
to die. Channels can be closed independently. to die. Channels can be closed independently.
@since 0.11 *) @since 0.11 *)
@ -114,25 +114,25 @@ val with_in : ?mode:int -> ?flags:Unix.open_flag list ->
(** Open an input file with the given optional flag list, calls the function (** Open an input file with the given optional flag list, calls the function
on the input channel. When the function raises or returns, the on the input channel. When the function raises or returns, the
channel is closed. channel is closed.
@param flags opening flags. [Unix.O_RDONLY] is used in any cases @param flags opening flags. [Unix.O_RDONLY] is used in any cases.
@since 0.16 *) @since 0.16 *)
val with_out : ?mode:int -> ?flags:Unix.open_flag list -> val with_out : ?mode:int -> ?flags:Unix.open_flag list ->
string -> f:(out_channel -> 'a) -> 'a string -> f:(out_channel -> 'a) -> 'a
(** Same as {!with_in} but for an output channel (** Same as {!with_in} but for an output channel.
@param flags opening flags (default [[Unix.O_CREAT; Unix.O_TRUNC]]) @param flags opening flags (default [[Unix.O_CREAT; Unix.O_TRUNC]])
[Unix.O_WRONLY] is used in any cases. [Unix.O_WRONLY] is used in any cases.
@since 0.16 *) @since 0.16 *)
val with_process_in : string -> f:(in_channel -> 'a) -> 'a val with_process_in : string -> f:(in_channel -> 'a) -> 'a
(** Open a subprocess and obtain a handle to its stdout (** Open a subprocess and obtain a handle to its stdout.
{[ {[
CCUnix.with_process_in "ls /tmp" ~f:CCIO.read_lines_l;; CCUnix.with_process_in "ls /tmp" ~f:CCIO.read_lines_l;;
]} ]}
@since 0.16 *) @since 0.16 *)
val with_process_out : string -> f:(out_channel -> 'a) -> 'a val with_process_out : string -> f:(out_channel -> 'a) -> 'a
(** Open a subprocess and obtain a handle to its stdin (** Open a subprocess and obtain a handle to its stdin.
@since 0.16 *) @since 0.16 *)
(** Handle to a subprocess. (** Handle to a subprocess.
@ -150,7 +150,7 @@ val with_process_full : ?env:string array -> string -> f:(process_full -> 'a) ->
@since 0.16 *) @since 0.16 *)
val with_connection : Unix.sockaddr -> f:(in_channel -> out_channel -> 'a) -> 'a val with_connection : Unix.sockaddr -> f:(in_channel -> out_channel -> 'a) -> 'a
(** Wrap {!Unix.open_connection} with a handler (** Wrap {!Unix.open_connection} with a handler.
@since 0.16 *) @since 0.16 *)
exception ExitServer exception ExitServer
@ -174,11 +174,11 @@ val with_file_lock : kind:[`Read|`Write] -> string -> (unit -> 'a) -> 'a
module Infix : sig module Infix : sig
val (?|) : ('a, Buffer.t, unit, call_result) format4 -> 'a val (?|) : ('a, Buffer.t, unit, call_result) format4 -> 'a
(** Infix version of {!call} (** Infix version of {!call}.
@since 0.11 *) @since 0.11 *)
val (?|&) : ('a, Buffer.t, unit, async_call_result) format4 -> 'a val (?|&) : ('a, Buffer.t, unit, async_call_result) format4 -> 'a
(** Infix version of {!async_call} (** Infix version of {!async_call}.
@since 0.11 *) @since 0.11 *)
end end