summaryrefslogtreecommitdiff
path: root/common.sml
diff options
context:
space:
mode:
Diffstat (limited to 'common.sml')
-rw-r--r--common.sml12
1 files changed, 10 insertions, 2 deletions
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