mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
remove buffer printers, rename pretty-printers to pp
This commit is contained in:
parent
d4d7bc1de2
commit
13b283a91d
32 changed files with 99 additions and 281 deletions
|
|
@ -9,6 +9,7 @@ type 'a gen = unit -> 'a option
|
|||
type 'a equal = 'a -> 'a -> bool
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
module type S = sig
|
||||
type 'a t
|
||||
|
|
@ -155,17 +156,11 @@ module type S = sig
|
|||
|
||||
(** {2 IO} *)
|
||||
|
||||
val pp: ?sep:string -> (Buffer.t -> 'a -> unit) ->
|
||||
Buffer.t -> 'a t -> unit
|
||||
val pp: ?sep:string -> 'a printer -> 'a t printer
|
||||
(** Print an array of items with printing function *)
|
||||
|
||||
val pp_i: ?sep:string -> (Buffer.t -> int -> 'a -> unit) ->
|
||||
Buffer.t -> 'a t -> unit
|
||||
val pp_i: ?sep:string -> (int -> 'a printer) -> 'a t printer
|
||||
(** Print an array, giving the printing function both index and item *)
|
||||
|
||||
val print : ?sep:string -> (Format.formatter -> 'a -> unit) ->
|
||||
Format.formatter -> 'a t -> unit
|
||||
(** Print an array of items with printing function *)
|
||||
end
|
||||
|
||||
(** {2 General Implementation}
|
||||
|
|
@ -299,22 +294,16 @@ let _choose a i j st =
|
|||
if i>=j then raise Not_found;
|
||||
a.(i+Random.State.int st (j-i))
|
||||
|
||||
let _pp ~sep pp_item buf a i j =
|
||||
let _pp ~sep pp_item out a i j =
|
||||
for k = i to j - 1 do
|
||||
if k > i then Buffer.add_string buf sep;
|
||||
pp_item buf a.(k)
|
||||
if k > i then (Format.pp_print_string out sep; Format.pp_print_cut out ());
|
||||
pp_item out a.(k)
|
||||
done
|
||||
|
||||
let _pp_i ~sep pp_item buf a i j =
|
||||
let _pp_i ~sep pp_item out a i j =
|
||||
for k = i to j - 1 do
|
||||
if k > i then Buffer.add_string buf sep;
|
||||
pp_item buf k a.(k)
|
||||
done
|
||||
|
||||
let _print ~sep pp_item fmt a i j =
|
||||
for k = i to j - 1 do
|
||||
if k > i then (Format.pp_print_string fmt sep; Format.pp_print_cut fmt ());
|
||||
pp_item fmt a.(k)
|
||||
if k > i then (Format.pp_print_string out sep; Format.pp_print_cut out ());
|
||||
pp_item k out a.(k)
|
||||
done
|
||||
|
||||
let _to_gen a i j =
|
||||
|
|
@ -654,11 +643,9 @@ let random_non_empty g st =
|
|||
let n = 1 + Random.State.int st 1_000 in
|
||||
random_len n g st
|
||||
|
||||
let pp ?(sep=", ") pp_item buf a = _pp ~sep pp_item buf a 0 (Array.length a)
|
||||
let pp ?(sep=", ") pp_item out a = _pp ~sep pp_item out a 0 (Array.length a)
|
||||
|
||||
let pp_i ?(sep=", ") pp_item buf a = _pp_i ~sep pp_item buf a 0 (Array.length a)
|
||||
|
||||
let print ?(sep=", ") pp_item fmt a = _print ~sep pp_item fmt a 0 (Array.length a)
|
||||
let pp_i ?(sep=", ") pp_item out a = _pp_i ~sep pp_item out a 0 (Array.length a)
|
||||
|
||||
let to_seq a k = iter k a
|
||||
|
||||
|
|
@ -900,10 +887,8 @@ module Sub = struct
|
|||
|
||||
let pp ?(sep=", ") pp_item buf a = _pp ~sep pp_item buf a.arr a.i a.j
|
||||
|
||||
let pp_i ?(sep=", ") pp_item buf a =
|
||||
_pp_i ~sep (fun out k x -> pp_item out (k-a.i) x) buf a.arr a.i a.j
|
||||
|
||||
let print ?(sep=", ") pp_item fmt a = _print ~sep pp_item fmt a.arr a.i a.j
|
||||
let pp_i ?(sep=", ") pp_item out a =
|
||||
_pp_i ~sep (fun k out x -> pp_item (k-a.i) out x) out a.arr a.i a.j
|
||||
|
||||
let to_seq a k = iter k a
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ type 'a gen = unit -> 'a option
|
|||
type 'a equal = 'a -> 'a -> bool
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
(** {2 Abstract Signature} *)
|
||||
|
||||
|
|
@ -157,17 +158,11 @@ module type S = sig
|
|||
|
||||
(** {2 IO} *)
|
||||
|
||||
val pp: ?sep:string -> (Buffer.t -> 'a -> unit) ->
|
||||
Buffer.t -> 'a t -> unit
|
||||
val pp: ?sep:string -> 'a printer -> 'a t printer
|
||||
(** Print an array of items with printing function *)
|
||||
|
||||
val pp_i: ?sep:string -> (Buffer.t -> int -> 'a -> unit) ->
|
||||
Buffer.t -> 'a t -> unit
|
||||
val pp_i: ?sep:string -> (int -> 'a printer) -> 'a t printer
|
||||
(** Print an array, giving the printing function both index and item *)
|
||||
|
||||
val print : ?sep:string -> (Format.formatter -> 'a -> unit) ->
|
||||
Format.formatter -> 'a t -> unit
|
||||
(** Print an array of items with printing function *)
|
||||
end
|
||||
|
||||
(** {2 Arrays} *)
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ let compare (a:bool) b = Pervasives.compare a b
|
|||
|
||||
let negate x = not x
|
||||
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
let pp buf = Printf.bprintf buf "%B"
|
||||
let print fmt = Format.pp_print_bool fmt
|
||||
let pp = Format.pp_print_bool
|
||||
|
|
|
|||
|
|
@ -13,10 +13,6 @@ val equal : t -> t -> bool
|
|||
val negate : t -> t
|
||||
(** Negation on booleans (functional version of [not]) *)
|
||||
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
val pp : t printer
|
||||
(** Printer for booleans *)
|
||||
|
||||
val print : t formatter
|
||||
|
|
|
|||
|
|
@ -42,12 +42,10 @@ let equal (a:float) b = a=b
|
|||
let hash = Hashtbl.hash
|
||||
let compare (a:float) b = Pervasives.compare a b
|
||||
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
let pp buf = Printf.bprintf buf "%f"
|
||||
let print fmt = Format.pp_print_float fmt
|
||||
let pp = Format.pp_print_float
|
||||
|
||||
let fsign a =
|
||||
if is_nan a then nan
|
||||
|
|
|
|||
|
|
@ -41,12 +41,10 @@ val equal : t -> t -> bool
|
|||
|
||||
val compare : t -> t -> int
|
||||
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
val pp : t printer
|
||||
val print : t formatter
|
||||
|
||||
val hash : t -> int
|
||||
|
||||
|
|
|
|||
|
|
@ -37,16 +37,14 @@ let pow a b =
|
|||
pow 0 1 = 0
|
||||
*)
|
||||
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
let random n st = Random.State.int st n
|
||||
let random_small = random 100
|
||||
let random_range i j st = i + random (j-i) st
|
||||
|
||||
let pp buf = Printf.bprintf buf "%d"
|
||||
let print fmt = Format.pp_print_int fmt
|
||||
let pp fmt = Format.pp_print_int fmt
|
||||
|
||||
let most_significant_bit =
|
||||
(-1) lxor ((-1) lsr 1)
|
||||
|
|
@ -79,7 +77,7 @@ let to_binary_gen (out:output) n =
|
|||
in
|
||||
loop false most_significant_bit n
|
||||
|
||||
let print_binary out n =
|
||||
let pp_binary out n =
|
||||
to_binary_gen (Format.pp_print_char out) n
|
||||
|
||||
let to_string_binary n =
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@ val pow : t -> t -> t
|
|||
Raises [Invalid_argument] if [a = b = 0] or [b] < 0.
|
||||
@since 0.11 *)
|
||||
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
val random : int -> t random_gen
|
||||
|
|
@ -32,7 +31,6 @@ val random_small : t random_gen
|
|||
val random_range : int -> int -> t random_gen
|
||||
|
||||
val pp : t printer
|
||||
val print : t formatter
|
||||
|
||||
val to_string : t -> string
|
||||
(** @since 0.13 *)
|
||||
|
|
@ -40,7 +38,7 @@ val to_string : t -> string
|
|||
val of_string : string -> t option
|
||||
(** @since 0.13 *)
|
||||
|
||||
val print_binary : t formatter
|
||||
val pp_binary : t printer
|
||||
(** prints as "0b00101010".
|
||||
@since 0.20 *)
|
||||
|
||||
|
|
|
|||
|
|
@ -1136,8 +1136,7 @@ end
|
|||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
let random_len len g st =
|
||||
|
|
@ -1221,17 +1220,7 @@ end
|
|||
|
||||
(** {2 IO} *)
|
||||
|
||||
let pp ?(start="") ?(stop="") ?(sep=", ") pp_item buf l =
|
||||
let rec print l = match l with
|
||||
| x::((_::_) as l) ->
|
||||
pp_item buf x;
|
||||
Buffer.add_string buf sep;
|
||||
print l
|
||||
| x::[] -> pp_item buf x
|
||||
| [] -> ()
|
||||
in Buffer.add_string buf start; print l; Buffer.add_string buf stop
|
||||
|
||||
let print ?(start="") ?(stop="") ?(sep=", ") pp_item fmt l =
|
||||
let pp ?(start="") ?(stop="") ?(sep=", ") pp_item fmt l =
|
||||
let rec print fmt l = match l with
|
||||
| x::((_::_) as l) ->
|
||||
pp_item fmt x;
|
||||
|
|
@ -1246,5 +1235,8 @@ let print ?(start="") ?(stop="") ?(sep=", ") pp_item fmt l =
|
|||
Format.pp_print_string fmt stop
|
||||
|
||||
(*$= & ~printer:(fun s->s)
|
||||
"[1, 2, 3]" (CCFormat.to_string (CCFormat.hbox(print ~start:"[" ~stop:"]" CCFormat.int)) [1;2;3])
|
||||
"[1, 2, 3]" \
|
||||
(CCFormat.to_string \
|
||||
(CCFormat.hbox(CCList.pp ~start:"[" ~stop:"]" CCFormat.int)) \
|
||||
[1;2;3])
|
||||
*)
|
||||
|
|
|
|||
|
|
@ -488,8 +488,7 @@ end
|
|||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
val random : 'a random_gen -> 'a t random_gen
|
||||
|
|
@ -533,6 +532,3 @@ end
|
|||
|
||||
val pp : ?start:string -> ?stop:string -> ?sep:string ->
|
||||
'a printer -> 'a t printer
|
||||
|
||||
val print : ?start:string -> ?stop:string -> ?sep:string ->
|
||||
'a formatter -> 'a t formatter
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
(** {1 Extensions of Standard Map} *)
|
||||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
module type S = sig
|
||||
include Map.S
|
||||
|
|
@ -55,10 +54,6 @@ module type S = sig
|
|||
val pp :
|
||||
?start:string -> ?stop:string -> ?arrow:string -> ?sep:string ->
|
||||
key printer -> 'a printer -> 'a t printer
|
||||
|
||||
val print :
|
||||
?start:string -> ?stop:string -> ?arrow:string -> ?sep:string ->
|
||||
key formatter -> 'a formatter -> 'a t formatter
|
||||
end
|
||||
|
||||
module Make(O : Map.OrderedType) = struct
|
||||
|
|
@ -113,19 +108,7 @@ module Make(O : Map.OrderedType) = struct
|
|||
let to_list m =
|
||||
fold (fun k v acc -> (k,v)::acc) m []
|
||||
|
||||
let pp ?(start="") ?(stop="") ?(arrow="->") ?(sep=", ") pp_k pp_v buf m =
|
||||
let first = ref true in
|
||||
Buffer.add_string buf start;
|
||||
iter
|
||||
(fun k v ->
|
||||
if !first then first := false else Buffer.add_string buf sep;
|
||||
pp_k buf k;
|
||||
Buffer.add_string buf arrow;
|
||||
pp_v buf v)
|
||||
m;
|
||||
Buffer.add_string buf stop
|
||||
|
||||
let print ?(start="") ?(stop="") ?(arrow="->") ?(sep=", ") pp_k pp_v fmt m =
|
||||
let pp ?(start="") ?(stop="") ?(arrow="->") ?(sep=", ") pp_k pp_v fmt m =
|
||||
Format.pp_print_string fmt start;
|
||||
let first = ref true in
|
||||
iter
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
@since 0.5 *)
|
||||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
module type S = sig
|
||||
include Map.S
|
||||
|
|
@ -58,10 +57,6 @@ module type S = sig
|
|||
val pp :
|
||||
?start:string -> ?stop:string -> ?arrow:string -> ?sep:string ->
|
||||
key printer -> 'a printer -> 'a t printer
|
||||
|
||||
val print :
|
||||
?start:string -> ?stop:string -> ?arrow:string -> ?sep:string ->
|
||||
key formatter -> 'a formatter -> 'a t formatter
|
||||
end
|
||||
|
||||
module Make(O : Map.OrderedType) : S
|
||||
|
|
|
|||
|
|
@ -147,8 +147,7 @@ end
|
|||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a fmt = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
let random g st =
|
||||
|
|
@ -184,10 +183,6 @@ let to_seq o k = match o with
|
|||
| None -> ()
|
||||
| Some x -> k x
|
||||
|
||||
let pp ppx buf o = match o with
|
||||
| None -> Buffer.add_string buf "None"
|
||||
| Some x -> Buffer.add_string buf "Some "; ppx buf x
|
||||
|
||||
let print ppx out = function
|
||||
let pp ppx out = function
|
||||
| None -> Format.pp_print_string out "None"
|
||||
| Some x -> Format.fprintf out "@[Some %a@]" ppx x
|
||||
|
|
|
|||
|
|
@ -130,8 +130,7 @@ val of_list : 'a list -> 'a t
|
|||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a fmt = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
val random : 'a random_gen -> 'a t random_gen
|
||||
|
|
@ -145,6 +144,3 @@ val to_gen : 'a t -> 'a gen
|
|||
val to_seq : 'a t -> 'a sequence
|
||||
|
||||
val pp : 'a printer -> 'a t printer
|
||||
|
||||
val print : 'a fmt -> 'a t fmt
|
||||
(** @since 0.13 *)
|
||||
|
|
|
|||
|
|
@ -42,11 +42,8 @@ let compare f g (x1,y1) (x2,y2) =
|
|||
let c = f x1 x2 in
|
||||
if c <> 0 then c else g y1 y2
|
||||
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
|
||||
let pp pp_x pp_y buf (x,y) =
|
||||
Printf.bprintf buf "(%a, %a)" pp_x x pp_y y
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
let print pa pb fmt (x,y) =
|
||||
Format.fprintf fmt "(%a, %a)" pa x pb y
|
||||
let pp ?(sep=", ") pa pb out (x,y) =
|
||||
Format.fprintf out "%a%s@,%a" pa x sep pb y
|
||||
|
|
|
|||
|
|
@ -63,9 +63,6 @@ val equal : ('a -> 'a -> bool) -> ('b -> 'b -> bool) -> ('a * 'b) -> ('a * 'b) -
|
|||
|
||||
val compare : ('a -> 'a -> int) -> ('b -> 'b -> int) -> ('a * 'b) -> ('a * 'b) -> int
|
||||
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
val pp : 'a printer -> 'b printer -> ('a*'b) printer
|
||||
|
||||
val print : 'a formatter -> 'b formatter -> ('a*'b) formatter
|
||||
val pp : ?sep:string -> 'a printer -> 'b printer -> ('a*'b) printer
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@
|
|||
|
||||
@since 0.9 *)
|
||||
|
||||
type 'a print = Format.formatter -> 'a -> unit
|
||||
type 'a pp = Buffer.t -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
type 'a eq = 'a -> 'a -> bool
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
|
|
@ -36,6 +35,4 @@ let equal f r1 r2 = f !r1 !r2
|
|||
let to_list r = [!r]
|
||||
let to_seq r yield = yield !r
|
||||
|
||||
let print pp_x fmt r = pp_x fmt !r
|
||||
|
||||
let pp pp_x buf r = pp_x buf !r
|
||||
let pp pp_x out r = pp_x out !r
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
(** {1 References}
|
||||
@since 0.9 *)
|
||||
|
||||
type 'a print = Format.formatter -> 'a -> unit
|
||||
type 'a pp = Buffer.t -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
type 'a eq = 'a -> 'a -> bool
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
|
|
@ -40,5 +39,4 @@ val to_list : 'a t -> 'a list
|
|||
|
||||
val to_seq : 'a t -> 'a sequence
|
||||
|
||||
val print : 'a print -> 'a t print
|
||||
val pp : 'a pp -> 'a t pp
|
||||
val pp : 'a printer -> 'a t printer
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a equal = 'a -> 'a -> bool
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
(** {2 Basics} *)
|
||||
|
||||
|
|
@ -257,18 +256,10 @@ let to_err = function
|
|||
|
||||
(** {2 IO} *)
|
||||
|
||||
let pp pp_x buf e = match e with
|
||||
| Ok x -> Printf.bprintf buf "ok(%a)" pp_x x
|
||||
| Error s -> Printf.bprintf buf "error(%s)" s
|
||||
|
||||
let pp' pp_x pp_e buf e = match e with
|
||||
| Ok x -> Printf.bprintf buf "ok(%a)" pp_x x
|
||||
| Error s -> Printf.bprintf buf "error(%a)" pp_e s
|
||||
|
||||
let print pp_x fmt e = match e with
|
||||
let pp pp_x fmt e = match e with
|
||||
| Ok x -> Format.fprintf fmt "@[ok(@,%a)@]" pp_x x
|
||||
| Error s -> Format.fprintf fmt "@[error(@,%s)@]" s
|
||||
|
||||
let print' pp_x pp_e fmt e = match e with
|
||||
let pp' pp_x pp_e fmt e = match e with
|
||||
| Ok x -> Format.fprintf fmt "@[ok(@,%a)@]" pp_x x
|
||||
| Error s -> Format.fprintf fmt "@[error(@,%a)@]" pp_e s
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@
|
|||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a equal = 'a -> 'a -> bool
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
(** {2 Basics} *)
|
||||
|
||||
|
|
@ -194,12 +193,4 @@ val to_err : ('a, 'b) t -> ('a, 'b) error
|
|||
val pp : 'a printer -> ('a, string) t printer
|
||||
|
||||
val pp': 'a printer -> 'e printer -> ('a, 'e) t printer
|
||||
(** Printer that is generic on the error type
|
||||
@since 0.19 *)
|
||||
|
||||
val print : 'a formatter -> ('a, string) t formatter
|
||||
|
||||
val print' : 'a formatter -> 'e formatter -> ('a, 'e) t formatter
|
||||
(** Printer that is generic on the error type
|
||||
@since 0.19 *)
|
||||
|
||||
(** Printer that is generic on the error type *)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
(** {1 Wrapper around Set} *)
|
||||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
module type S = sig
|
||||
include Set.S
|
||||
|
|
@ -27,10 +26,6 @@ module type S = sig
|
|||
val pp :
|
||||
?start:string -> ?stop:string -> ?sep:string ->
|
||||
elt printer -> t printer
|
||||
|
||||
val print :
|
||||
?start:string -> ?stop:string -> ?sep:string ->
|
||||
elt formatter -> t formatter
|
||||
end
|
||||
|
||||
module Make(O : Map.OrderedType) = struct
|
||||
|
|
@ -51,17 +46,7 @@ module Make(O : Map.OrderedType) = struct
|
|||
|
||||
let to_list = elements
|
||||
|
||||
let pp ?(start="") ?(stop="") ?(sep=", ") pp_x buf m =
|
||||
let first = ref true in
|
||||
Buffer.add_string buf start;
|
||||
iter
|
||||
(fun x ->
|
||||
if !first then first := false else Buffer.add_string buf sep;
|
||||
pp_x buf x)
|
||||
m;
|
||||
Buffer.add_string buf stop
|
||||
|
||||
let print ?(start="") ?(stop="") ?(sep=", ") pp_x fmt m =
|
||||
let pp ?(start="") ?(stop="") ?(sep=", ") pp_x fmt m =
|
||||
Format.pp_print_string fmt start;
|
||||
let first = ref true in
|
||||
iter
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
@since 0.9 *)
|
||||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
module type S = sig
|
||||
include Set.S
|
||||
|
|
@ -29,10 +28,6 @@ module type S = sig
|
|||
val pp :
|
||||
?start:string -> ?stop:string -> ?sep:string ->
|
||||
elt printer -> t printer
|
||||
|
||||
val print :
|
||||
?start:string -> ?stop:string -> ?sep:string ->
|
||||
elt formatter -> t formatter
|
||||
end
|
||||
|
||||
module Make(O : Set.OrderedType) : S
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
|||
type 'a gen = unit -> 'a option
|
||||
type 'a equal = 'a -> 'a -> bool
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
(** A vector of 'a. *)
|
||||
type ('a,'mut) t = {
|
||||
|
|
@ -737,16 +736,7 @@ let to_klist v =
|
|||
else `Cons (v.vec.(i), aux (i+1))
|
||||
in aux 0
|
||||
|
||||
let pp ?(start="") ?(stop="") ?(sep=", ") pp_item buf v =
|
||||
Buffer.add_string buf start;
|
||||
iteri
|
||||
(fun i x ->
|
||||
if i > 0 then Buffer.add_string buf sep;
|
||||
pp_item buf x
|
||||
) v;
|
||||
Buffer.add_string buf stop
|
||||
|
||||
let print ?(start="") ?(stop="") ?(sep=", ") pp_item fmt v =
|
||||
let pp ?(start="") ?(stop="") ?(sep=", ") pp_item fmt v =
|
||||
Format.pp_print_string fmt start;
|
||||
iteri
|
||||
(fun i x ->
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@ type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
|||
type 'a gen = unit -> 'a option
|
||||
type 'a equal = 'a -> 'a -> bool
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
val freeze : ('a, _) t -> ('a, ro) t
|
||||
(** Make an immutable vector (no copy! Don't use the old version)*)
|
||||
|
|
@ -275,6 +274,3 @@ val to_gen : ('a,_) t -> 'a gen
|
|||
|
||||
val pp : ?start:string -> ?stop:string -> ?sep:string ->
|
||||
'a printer -> ('a,_) t printer
|
||||
|
||||
val print : ?start:string -> ?stop:string -> ?sep:string ->
|
||||
'a formatter -> ('a,_) t formatter
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
(** {1 Persistent hash-table on top of OCaml's hashtables} *)
|
||||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a equal = 'a -> 'a -> bool
|
||||
|
||||
module type HashedType = sig
|
||||
|
|
@ -111,9 +110,7 @@ module type S = sig
|
|||
|
||||
val equal : 'a equal -> 'a t equal
|
||||
|
||||
val pp : key printer -> 'a printer -> 'a t printer
|
||||
|
||||
val print : key formatter -> 'a formatter -> 'a t formatter
|
||||
val pp : ?sep:string -> ?arrow:string -> key printer -> 'a printer -> 'a t printer
|
||||
|
||||
val stats : _ t -> Hashtbl.statistics
|
||||
(** Statistics on the internal table.
|
||||
|
|
@ -636,26 +633,15 @@ module Make(H : HashedType) : S with type key = H.t = struct
|
|||
| Some v' -> eq v v'
|
||||
) t1
|
||||
|
||||
let pp pp_k pp_v buf t =
|
||||
Buffer.add_string buf "{";
|
||||
let first = ref true in
|
||||
iter t
|
||||
(fun k v ->
|
||||
if !first then first:=false else Buffer.add_string buf ", ";
|
||||
Printf.bprintf buf "%a -> %a" pp_k k pp_v v
|
||||
);
|
||||
Buffer.add_string buf "}"
|
||||
|
||||
let print pp_k pp_v fmt t =
|
||||
Format.pp_print_string fmt "{";
|
||||
let pp ?(sep=",") ?(arrow="->") pp_k pp_v fmt t =
|
||||
let first = ref true in
|
||||
iter t
|
||||
(fun k v ->
|
||||
if !first then first:=false
|
||||
else (Format.pp_print_string fmt ", "; Format.pp_print_cut fmt ());
|
||||
Format.fprintf fmt "%a -> %a" pp_k k pp_v v
|
||||
else (Format.pp_print_string fmt sep; Format.pp_print_cut fmt ());
|
||||
Format.fprintf fmt "%a %s %a" pp_k k arrow pp_v v
|
||||
);
|
||||
Format.pp_print_string fmt "}"
|
||||
()
|
||||
|
||||
let stats t =
|
||||
let a = reroot_ t in
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ old values).
|
|||
This module is not thread-safe. *)
|
||||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a equal = 'a -> 'a -> bool
|
||||
|
||||
module type HashedType = sig
|
||||
|
|
@ -118,9 +117,7 @@ module type S = sig
|
|||
|
||||
val equal : 'a equal -> 'a t equal
|
||||
|
||||
val pp : key printer -> 'a printer -> 'a t printer
|
||||
|
||||
val print : key formatter -> 'a formatter -> 'a t formatter
|
||||
val pp : ?sep:string -> ?arrow:string -> key printer -> 'a printer -> 'a t printer
|
||||
|
||||
val stats : _ t -> Hashtbl.statistics
|
||||
(** Statistics on the internal table.
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ type 'a sequence = ('a -> unit) -> unit
|
|||
type 'a gen = unit -> 'a option
|
||||
type 'a equal = 'a -> 'a -> bool
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
type + 'a t = unit ->
|
||||
[ `Nil
|
||||
|
|
@ -528,16 +527,7 @@ end
|
|||
|
||||
(** {2 IO} *)
|
||||
|
||||
let pp ?(sep=",") pp_item buf l =
|
||||
let rec pp buf l = match l() with
|
||||
| `Nil -> ()
|
||||
| `Cons (x,l') -> Buffer.add_string buf sep; pp_item buf x; pp buf l'
|
||||
in
|
||||
match l() with
|
||||
| `Nil -> ()
|
||||
| `Cons (x,l') -> pp_item buf x; pp buf l'
|
||||
|
||||
let print ?(sep=",") pp_item fmt l =
|
||||
let pp ?(sep=",") pp_item fmt l =
|
||||
let rec pp fmt l = match l() with
|
||||
| `Nil -> ()
|
||||
| `Cons (x,l') ->
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ type 'a sequence = ('a -> unit) -> unit
|
|||
type 'a gen = unit -> 'a option
|
||||
type 'a equal = 'a -> 'a -> bool
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
(** {2 Basics} *)
|
||||
|
||||
|
|
@ -270,7 +269,3 @@ val of_gen : 'a gen -> 'a t
|
|||
val pp : ?sep:string -> 'a printer -> 'a t printer
|
||||
(** Print the list with the given separator (default ",").
|
||||
Does not print opening/closing delimiters *)
|
||||
|
||||
val print : ?sep:string -> 'a formatter -> 'a t formatter
|
||||
(** Print the list with the given separator (default ",").
|
||||
Does not print opening/closing delimiters *)
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ is a structural type. *)
|
|||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
type +'a t = unit -> [`Nil | `Node of 'a * 'a t list]
|
||||
|
||||
|
|
@ -186,7 +185,7 @@ let find ?pset f t =
|
|||
|
||||
(** {2 Pretty-printing} *)
|
||||
|
||||
let print pp_x fmt t =
|
||||
let pp pp_x fmt t =
|
||||
(* at depth [lvl] *)
|
||||
let rec pp fmt t = match t with
|
||||
| `Nil -> ()
|
||||
|
|
@ -273,7 +272,7 @@ module Dot = struct
|
|||
Format.pp_print_char fmt ',';
|
||||
_pp_attrs fmt l'
|
||||
|
||||
let print fmt (name,l) =
|
||||
let pp out (name,l) =
|
||||
(* nodes already printed *)
|
||||
let tbl = Hashtbl.create 32 in
|
||||
(* fresh name generator *)
|
||||
|
|
@ -303,11 +302,11 @@ module Dot = struct
|
|||
let name, attrs = get_name x in
|
||||
begin match parent with
|
||||
| None -> ()
|
||||
| Some n -> Format.fprintf fmt " %s -> %s;@," n name
|
||||
| Some n -> Format.fprintf out " %s -> %s;@," n name
|
||||
end;
|
||||
if not (Hashtbl.mem tbl name) then (
|
||||
Hashtbl.add tbl name ();
|
||||
Format.fprintf fmt "@[%s [%a];@]@," name _pp_attrs attrs;
|
||||
Format.fprintf out "@[%s [%a];@]@," name _pp_attrs attrs;
|
||||
List.fold_left
|
||||
(fun q y -> FQ.push q (Some name, y)) q l
|
||||
) else q
|
||||
|
|
@ -318,23 +317,18 @@ module Dot = struct
|
|||
FQ.empty l
|
||||
in
|
||||
(* preamble *)
|
||||
Format.fprintf fmt "@[<hv 2>digraph \"%s\" {@," name;
|
||||
Format.fprintf out "@[<hv 2>digraph \"%s\" {@," name;
|
||||
aux q;
|
||||
Format.fprintf fmt "}@]@.";
|
||||
Format.fprintf out "}@]@.";
|
||||
()
|
||||
|
||||
let pp buf t =
|
||||
let fmt = Format.formatter_of_buffer buf in
|
||||
print fmt t;
|
||||
Format.pp_print_flush fmt ()
|
||||
|
||||
let pp_single name buf t = pp buf (singleton ~name t)
|
||||
let pp_single name out t = pp out (singleton ~name t)
|
||||
|
||||
let print_to_file filename g =
|
||||
let oc = open_out filename in
|
||||
let fmt = Format.formatter_of_out_channel oc in
|
||||
try
|
||||
print fmt g;
|
||||
pp fmt g;
|
||||
Format.pp_print_flush fmt ();
|
||||
close_out oc
|
||||
with e ->
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ is a structural type. *)
|
|||
type 'a sequence = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a printer = Buffer.t -> 'a -> unit
|
||||
type 'a formatter = Format.formatter -> 'a -> unit
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
(** {2 Basics} *)
|
||||
|
||||
|
|
@ -119,7 +118,7 @@ Example (tree of calls for naive Fibonacci function):
|
|||
]}
|
||||
*)
|
||||
|
||||
val print : 'a formatter -> 'a t formatter
|
||||
val pp : 'a printer -> 'a t printer
|
||||
(** A pretty-printer using S-expressions and boxes to render the tree.
|
||||
Empty nodes are not rendered; sharing is ignored.
|
||||
@since 0.9 *)
|
||||
|
|
@ -150,13 +149,10 @@ module Dot : sig
|
|||
|
||||
val singleton : name:string -> attribute list t -> graph
|
||||
|
||||
val pp : graph printer
|
||||
(** Print the graph in DOT *)
|
||||
|
||||
val pp_single : string -> attribute list t printer
|
||||
|
||||
val print : graph formatter
|
||||
(** Printer with indentation, etc.
|
||||
val pp : graph printer
|
||||
(** Printer to DOT with indentation, etc.
|
||||
@since 0.6.1 *)
|
||||
|
||||
val print_to_file : string -> graph -> unit
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ exception ParseError of line_num * col_num * (unit -> string)
|
|||
|
||||
let l = CCList.(1 -- n) in
|
||||
let l_printed =
|
||||
CCFormat.to_string (CCList.print ~sep:"," ~start:"[" ~stop:"]" CCInt.print) l in
|
||||
CCFormat.(to_string (list ~start:"[" ~stop:"]" ~sep:"," int)) l in
|
||||
|
||||
let l' = CCParse.parse_string_exn ~p l_printed in
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ exception ParseError of line_num * col_num * (unit -> string)
|
|||
(fun oc ->
|
||||
let fmt = Format.formatter_of_out_channel oc in
|
||||
Format.fprintf fmt "@[%a@]@."
|
||||
(CCList.print ~sep:"," ~start:"[" ~stop:"]" CCInt.print) l);
|
||||
CCFormat.(list ~start:"[" ~stop:"]" ~sep:"," int) l);
|
||||
(* parse it back *)
|
||||
CCParse.parse_file_exn ~size:1024 ~file:name ~p)
|
||||
in
|
||||
|
|
|
|||
|
|
@ -15,22 +15,22 @@ let install_printer s =
|
|||
()
|
||||
let install_printers = List.iter install_printer
|
||||
|
||||
let pp_rw_vector pp_x out (v: _ CCVector.vector) = CCVector.print pp_x out v
|
||||
let pp_ro_vector pp_x out (v: _ CCVector.ro_vector) = CCVector.print pp_x out v
|
||||
let pp_klist (ppx:Format.formatter -> 'a -> unit) out l = CCKList.print ppx out l
|
||||
let pp_rw_vector pp_x out (v: _ CCVector.vector) = CCVector.pp pp_x out v
|
||||
let pp_ro_vector pp_x out (v: _ CCVector.ro_vector) = CCVector.pp pp_x out v
|
||||
let pp_klist (ppx:Format.formatter -> 'a -> unit) out l = CCKList.pp ppx out l
|
||||
|
||||
let () =
|
||||
install_printers
|
||||
[ "CCHashtbl.print"
|
||||
[ "CCHashtbl.pp"
|
||||
; "Containers_top.pp_rw_vector"
|
||||
; "Containers_top.pp_ro_vector"
|
||||
; "CCBV.print"
|
||||
; "CCDeque.print"
|
||||
; "CCFQueue.print"
|
||||
; "CCIntMap.print"
|
||||
; "CCPersistentArray.print"
|
||||
; "CCBigstring.print"
|
||||
; "CCBV.pp"
|
||||
; "CCDeque.pp"
|
||||
; "CCFQueue.pp"
|
||||
; "CCIntMap.pp"
|
||||
; "CCPersistentArray.pp"
|
||||
; "CCBigstring.pp"
|
||||
; "Containers_top.pp_klist"
|
||||
; "CCKTree.print"
|
||||
; "CCSexpM.print"
|
||||
; "CCKTree.pp"
|
||||
; "CCSexpM.pp"
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue