From 3a0b1f9e1612254587f4794029e0f111fbd640a5 Mon Sep 17 00:00:00 2001 From: Adrien Guatto Date: Mon, 19 Jul 2010 15:13:56 +0200 Subject: [PATCH] New handy function for pretty-printing: wrap_print. --- compiler/utilities/misc.ml | 4 ++++ compiler/utilities/misc.mli | 3 +++ 2 files changed, 7 insertions(+) diff --git a/compiler/utilities/misc.ml b/compiler/utilities/misc.ml index b191a77..a63fb59 100644 --- a/compiler/utilities/misc.ml +++ b/compiler/utilities/misc.ml @@ -245,3 +245,7 @@ let mapi3 f l1 l2 l3 = (f i v1 v2 v3)::(aux (i+1) l1 l2 l3) in aux 0 l1 l2 l3 + +let wrap_print pp out x = + let fmt = Format.formatter_of_out_channel out in + Format.fprintf fmt "%a@." pp x diff --git a/compiler/utilities/misc.mli b/compiler/utilities/misc.mli index 909558b..5ccc16e 100644 --- a/compiler/utilities/misc.mli +++ b/compiler/utilities/misc.mli @@ -179,3 +179,6 @@ val mapi2: (int -> 'a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list val mapi3: (int -> 'a -> 'b -> 'c -> 'd) -> 'a list -> 'b list -> 'c list -> 'd list +(** Enable the use of a plain pretty-printing function with an output channel + instead of a formatter. *) +val wrap_print : (Format.formatter -> 'a -> unit) -> out_channel -> 'a -> unit