[MLton-commit] r6769
Matthew Fluet
fluet at mlton.org
Tue Aug 19 15:16:42 PDT 2008
Use Array.unfoldi.
----------------------------------------------------------------------
U mlton/trunk/basis-library/util/CUtil.sml
----------------------------------------------------------------------
Modified: mlton/trunk/basis-library/util/CUtil.sml
===================================================================
--- mlton/trunk/basis-library/util/CUtil.sml 2008-08-19 22:16:31 UTC (rev 6768)
+++ mlton/trunk/basis-library/util/CUtil.sml 2008-08-19 22:16:41 UTC (rev 6769)
@@ -25,14 +25,11 @@
sub: 'a * int -> 'b,
n: int) : 'b array =
let
- val a = Array.arrayUninit n
- fun loop i =
- if i >= n
- then ()
- else (Array.unsafeUpdate (a, i, sub (s, i))
- ; loop (i +? 1))
- val () = loop 0
- in
+ val (a, _) =
+ Array.unfoldi
+ (n, (), fn (i, ()) =>
+ (sub (s, i), ()))
+ in
a
end
@@ -97,14 +94,12 @@
*)
fun fromList l =
let
- val n = List.length l
- val a = Array.arrayUninit (1 +? n)
- val _ =
- List.foldl (fn (s, i) =>
- (Array.unsafeUpdate (a, i, NullString.nullTerm s)
- ; i +? 1))
- 0 l
- val _ = Array.unsafeUpdate (a, n, NullString.empty)
+ val (a, _) =
+ Array.unfoldi
+ (1 +? List.length l, l, fn (_, l) =>
+ case l of
+ [] => (NullString.empty, l)
+ | s::l => (NullString.nullTerm s, l))
in
a
end
More information about the MLton-commit
mailing list