From af4c3fc19545375b469b166d63c5d344b261a7f4 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 3 Nov 2016 15:56:02 +0100 Subject: [PATCH] change boxing in CCFormat.Dump; add example/doc --- src/core/CCFormat.ml | 4 ++-- src/core/CCFormat.mli | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/core/CCFormat.ml b/src/core/CCFormat.ml index 9b1fddaa..a02f6b23 100644 --- a/src/core/CCFormat.ml +++ b/src/core/CCFormat.ml @@ -334,8 +334,8 @@ module Dump = struct let int32 = int32 let int64 = int64 let nativeint = nativeint - let list pp = hovbox (list ~start:"[" ~stop:"]" ~sep:";" pp) - let array pp = hovbox (array ~start:"[|" ~stop:"|]" ~sep:";" pp) + let list pp = within "[" "]" (hovbox (list ~sep:";" pp)) + let array pp = within "[|" "|]" (hovbox (array ~sep:";" pp)) let option pp out x = match x with | None -> Format.pp_print_string out "None" | Some x -> Format.fprintf out "Some %a" pp x diff --git a/src/core/CCFormat.mli b/src/core/CCFormat.mli index 9db0a194..ec7c6efd 100644 --- a/src/core/CCFormat.mli +++ b/src/core/CCFormat.mli @@ -204,7 +204,15 @@ val to_file : string -> ('a, t, unit, unit) format4 -> 'a (** {2 Dump} Print structures as OCaml values, so that they can be parsed back - by OCaml (typically, in the toplevel, for debugging) + by OCaml (typically, in the toplevel, for debugging). + + Example: + {[ + Format.printf "%a@." CCFormat.Dump.(list int) CCList.(1 -- 200);; + + Format.printf "%a@." CCFormat.Dump.(array (list (pair int bool))) + [| [1, true; 2, false]; []; [42, false] |];; + ]} @since NEXT_RELEASE *) @@ -215,11 +223,10 @@ module Dump : sig val string : string t val bool : bool t val float : float t - val char : char t (** @since 0.14 *) - val int32 : int32 t (** @since 0.14 *) - val int64 : int64 t (** @since 0.14 *) - val nativeint : nativeint t (** @since 0.14 *) - + val char : char t + val int32 : int32 t + val int64 : int64 t + val nativeint : nativeint t val list : 'a t -> 'a list t val array : 'a t -> 'a array t val option : 'a t -> 'a option t