[MLton-commit] r6664
Vesa Karvonen
vesak at mlton.org
Tue Jul 1 15:15:52 PDT 2008
Added primed formatters D', G', I', and R' that use "-" as sign rather
than SML's "~".
----------------------------------------------------------------------
U mltonlib/trunk/com/ssh/extended-basis/unstable/detail/text/cvt.sml
U mltonlib/trunk/com/ssh/extended-basis/unstable/public/text/cvt.sig
----------------------------------------------------------------------
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/text/cvt.sml
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/text/cvt.sml 2008-07-01 18:53:59 UTC (rev 6663)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/text/cvt.sml 2008-07-01 22:15:50 UTC (rev 6664)
@@ -1,4 +1,4 @@
-(* Copyright (C) 2007 Vesa Karvonen
+(* Copyright (C) 2007-2008 Vesa Karvonen
*
* This code is released under the MLton license, a BSD-style license.
* See the LICENSE file or http://mlton.org/License for details.
@@ -11,30 +11,40 @@
type ('c, 's) sel = ('c -> 's) -> 's
+ val fixSign = BasisString.map (fn #"~" => #"-" | other => other)
+
val C = str
val B = Bool.toString
- val D = Int.toString
+ val D = Int.toString
+ val D' = fixSign o Int.toString
val X = Word.toString
val G = Real.toString
+ val G' = fixSign o Real.toString
- fun I k = k {b = Int.fmt BIN,
- o = Int.fmt OCT,
- d = Int.fmt DEC,
- x = Int.fmt HEX}
+ fun mk fmt k = k {b = fmt BIN,
+ o = fmt OCT,
+ d = fmt DEC,
+ x = fmt HEX}
+ fun I k = mk Int.fmt k
+ fun I' k = mk (fn c => fixSign o Int.fmt c) k
+
fun W k = k {b = Word.fmt BIN,
o = Word.fmt OCT,
d = Word.fmt DEC,
x = Word.fmt HEX}
- fun R k = k {s = Real.fmt (SCI NONE),
- S = Real.fmt o SCI o SOME,
- f = Real.fmt (FIX NONE),
- F = Real.fmt o FIX o SOME,
- g = Real.fmt (GEN NONE),
- G = Real.fmt o GEN o SOME,
- e = Real.fmt EXACT}
+ fun mk fmt k = k {s = fmt (SCI NONE),
+ S = fmt o SCI o SOME,
+ f = fmt (FIX NONE),
+ F = fmt o FIX o SOME,
+ g = fmt (GEN NONE),
+ G = fmt o GEN o SOME,
+ e = fmt EXACT}
+ fun R k = mk Real.fmt k
+ fun R' k = mk (fn c => fixSign o Real.fmt c) k
+
fun seq prefix suffix foldr full get c xs =
case get (full xs)
of NONE => prefix ^ suffix
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/text/cvt.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/text/cvt.sig 2008-07-01 18:53:59 UTC (rev 6663)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/text/cvt.sig 2008-07-01 22:15:50 UTC (rev 6664)
@@ -1,4 +1,4 @@
-(* Copyright (C) 2007 Vesa Karvonen
+(* Copyright (C) 2007-2008 Vesa Karvonen
*
* This code is released under the MLton license, a BSD-style license.
* See the LICENSE file or http://mlton.org/License for details.
@@ -22,6 +22,9 @@
* in scientific notation with 3 digits after the decimal point. To do
* that you could write {R#S 3 aReal}, which is equivalent to {Real.fmt
* (StringCvt.SCI (SOME 3)) aReal}.
+ *
+ * The primed formatters {D'}, {G'}, {I'}, and {R'} use "-" as sign rather
+ * than SML's "~".
*)
signature CVT = sig
type 'a t = 'a -> String.t
@@ -35,8 +38,10 @@
val C : Char.t t (** Same as {str}. *)
val B : Bool.t t (** Same as {Bool.toString}. *)
val D : Int.t t (** Same as {Int.toString} and {I#d}. *)
+ val D': Int.t t
val X : Word.t t (** Same as {Word.toString} and {W#x}. *)
val G : Real.t t (** Same as {Real.toString} and {R#g}. *)
+ val G': Real.t t
val I : ({b : Int.t t (** {I#b = Int.fmt BIN} *)
, o : Int.t t (** {I#o = Int.fmt OCT} *)
@@ -44,6 +49,12 @@
, x : Int.t t (** {I#x = Int.fmt HEX} *)
}, 'k) sel
+ val I': ({b : Int.t t
+ , o : Int.t t
+ , d : Int.t t
+ , x : Int.t t
+ }, 'k) sel
+
val W : ({b : Word.t t (** {W#b = Word.fmt BIN} *)
, o : Word.t t (** {W#o = Word.fmt OCT} *)
, d : Word.t t (** {W#d = Word.fmt DEC} *)
@@ -59,6 +70,15 @@
, e : Real.t t (** {R#e = Real.fmt EXACT} *)
}, 'k) sel
+ val R': ({s : Real.t t
+ , S : Int.t -> Real.t t
+ , f : Real.t t
+ , F : Int.t -> Real.t t
+ , g : Real.t t
+ , G : Int.t -> Real.t t
+ , e : Real.t t
+ }, 'k) sel
+
(** == Formatter Combinators == *)
val A : 'a t -> 'a Array.t t (** Makes a formatter for arrays. *)
More information about the MLton-commit
mailing list