From 183a4420d2f2a985dd26d76e63c2cdcaafedc5ad Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Sun, 18 May 2025 12:07:58 +0200 Subject: Conditional inclusion --- common.sml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'common.sml') diff --git a/common.sml b/common.sml index d00b1a8..31a9940 100644 --- a/common.sml +++ b/common.sml @@ -108,6 +108,14 @@ fun output stream s = TextIO.output (stream, s) fun fprint stream g = Fold.fold ((false, output stream), fn _ => ()) g fun printf g = fprint TextIO.stdOut g +fun sprintf g = +let + val buf = ref [] + fun output s = (buf := s :: (!buf)) + fun finish _ = String.concat (rev (!buf)) +in + Fold.fold ((false, output), finish) +end g fun Printf output g = Fold.fold ((false, output), fn _ => ()) g local @@ -122,14 +130,14 @@ in (ifF ign (fn () => f (output, v)); (ign, output))) z end -fun Ign z = Fold.step1 (fn (_, (_, output)) => (true, output)) z +fun Ign z = Fold.step0 (fn (_, output) => (true, output)) z fun bind A f = fn z => Fold.fold z A f fun bindWith2str to = bind A1 (fn (output, v) => output (to v)) val I = fn z => bindWith2str Int.toString z val C = fn z => bindWith2str str z -val B = fn z => bindWith2str (fn true => "true" | false => "false") z +val B = fn z => bindWith2str Bool.toString z val R = fn z => bind A1 (fn (output, n) => app (fn f => f ()) (List.tabulate (n, fn _ => fn () => output "\t"))) z -- cgit v1.2.3