From 92aad159c8e19f53b6ff906ec5f3a976a2424661 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 11 Jun 2021 12:39:02 -0400 Subject: [PATCH] add `CCFormat.{const_string,opaque}` --- src/core/CCFormat.ml | 5 ++++- src/core/CCFormat.mli | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/CCFormat.ml b/src/core/CCFormat.ml index 9c88a3f6..192a9597 100644 --- a/src/core/CCFormat.ml +++ b/src/core/CCFormat.ml @@ -8,7 +8,7 @@ type 'a iter = ('a -> unit) -> unit include Format type t = Format.formatter -type 'a printer = t -> 'a -> unit +type -'a printer = t -> 'a -> unit (** {2 Combinators} *) @@ -182,6 +182,9 @@ let some pp out = function | None -> () | Some x -> pp out x +let const_string s out _ = string out s +let opaque out _ = string out "opaque" + let lazy_force pp out (lazy x) = pp out x let lazy_or ?(default=return "") pp out x = diff --git a/src/core/CCFormat.mli b/src/core/CCFormat.mli index 0a09c064..0be0cdd8 100644 --- a/src/core/CCFormat.mli +++ b/src/core/CCFormat.mli @@ -14,7 +14,7 @@ include module type of struct include Format end (** {{: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html} Documentation for the standard Format module}*) type t = Format.formatter -type 'a printer = t -> 'a -> unit +type -'a printer = t -> 'a -> unit (** {2 Combinators} *) @@ -167,6 +167,16 @@ val some : 'a printer -> 'a option printer @since 1.0 *) +val const_string : string -> 'a printer +(** [const_string s] is a printer that ignores its input and + always prints [s]. + @since NEXT_RELEASE *) + +val opaque : 'a printer +(** [opaque] is [const_string "opaque"]. + The exact string used is not stable. + @since NEXT_RELEASE *) + val lazy_force : 'a printer -> 'a lazy_t printer (** [lazy_force pp out x] forces [x] and prints the result with [pp]. @since 2.0 *)