[MLton] Minor simplification to NumericLiteral
Vesa Karvonen
vesa.karvonen@cs.helsinki.fi
Sat, 27 May 2006 16:20:51 +0300
I noticed that the Wiki version of the make function requires
unnecessarily many operations. In particular, op < and x2s can be
removed. The only difference is that the Fail message may look different
compared to the Wiki version. However, the Fail message is now arguably
more consistent, because the values are now always printed as decimal
integers. Here is the simplified Num module:
structure Num =
struct
fun make (op *, op +, i2x) iBase =
let
val xBase = i2x iBase
in
Fold.fold
((i2x 0,
fn (i, x) =>
if 0 <= i andalso i < iBase then
x * xBase + i2x i
else
raise Fail (concat
["Num: ", Int.toString i,
" is not a valid\
\ digit in base " ^
Int.toString iBase])),
fst)
end
fun I ? = make (op *, op +, id) ?
fun II ? = make (op *, op +, IntInf.fromInt) ?
fun W ? = make (op *, op +, Word.fromInt) ?
fun ` ? = Fold.step1 (fn (i, (x, step)) =>
(step (i, x), step)) ?
val a = 10
val b = 11
val c = 12
val d = 13
val e = 14
val f = 15
end
where
fun fst (x, _) = x
I'll update the Wiki with this simpler Num module shortly.
-Vesa Karvonen