[MLton-commit] r4387
Stephen Weeks
MLton@mlton.org
Thu, 30 Mar 2006 12:10:00 -0800
Changed unfoldi to return the state in addition to the created
object.
----------------------------------------------------------------------
U mlton/trunk/basis-library/arrays-and-vectors/array.sig
U mlton/trunk/basis-library/arrays-and-vectors/mono-array.sig
U mlton/trunk/basis-library/arrays-and-vectors/mono-vector.sig
U mlton/trunk/basis-library/arrays-and-vectors/sequence.fun
U mlton/trunk/basis-library/arrays-and-vectors/sequence.sig
U mlton/trunk/basis-library/arrays-and-vectors/vector.sig
U mlton/trunk/basis-library/mlton/array.sig
U mlton/trunk/basis-library/mlton/vector.sig
----------------------------------------------------------------------
Modified: mlton/trunk/basis-library/arrays-and-vectors/array.sig
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/array.sig 2006-03-30 11:07:48 UTC (rev 4386)
+++ mlton/trunk/basis-library/arrays-and-vectors/array.sig 2006-03-30 20:09:58 UTC (rev 4387)
@@ -40,17 +40,13 @@
structure ArraySlice: ARRAY_SLICE_EXTRA
- val rawArray: int -> 'a array
- val unsafeSub: 'a array * int -> 'a
- val unsafeUpdate: 'a array * int * 'a -> unit
-
+ val checkSlice: 'a array * int * int option -> int (* Deprecated *)
+ val checkSliceMax: int * int option * int -> int (* Deprecated *)
val concat: 'a array list -> 'a array
val duplicate: 'a array -> 'a array
+ val rawArray: int -> 'a array
val toList: 'a array -> 'a list
- val unfoldi: int * 'a * (int * 'a -> 'b * 'a) -> 'b array
-
- (* Deprecated *)
- val checkSlice: 'a array * int * int option -> int
- (* Deprecated *)
- val checkSliceMax: int * int option * int -> int
+ val unfoldi: int * 'b * (int * 'b -> 'a * 'b) -> 'a array * 'b
+ val unsafeSub: 'a array * int -> 'a
+ val unsafeUpdate: 'a array * int * 'a -> unit
end
Modified: mlton/trunk/basis-library/arrays-and-vectors/mono-array.sig
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/mono-array.sig 2006-03-30 11:07:48 UTC (rev 4386)
+++ mlton/trunk/basis-library/arrays-and-vectors/mono-array.sig 2006-03-30 20:09:58 UTC (rev 4387)
@@ -45,7 +45,7 @@
val rawArray: int -> array
val toList: array -> elem list
val toPoly: array -> elem Array.array
- val unfoldi: int * 'a * (int * 'a -> elem * 'a) -> array
+ val unfoldi: int * 'a * (int * 'a -> elem * 'a) -> array * 'a
val unsafeSub: array * int -> elem
val unsafeUpdate: array * int * elem -> unit
end
Modified: mlton/trunk/basis-library/arrays-and-vectors/mono-vector.sig
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/mono-vector.sig 2006-03-30 11:07:48 UTC (rev 4386)
+++ mlton/trunk/basis-library/arrays-and-vectors/mono-vector.sig 2006-03-30 20:09:58 UTC (rev 4387)
@@ -41,7 +41,7 @@
val toList: vector -> elem list
val tokens: (elem -> bool) -> vector -> vector list
val translate: (elem -> vector) -> vector -> vector
- val unfoldi: int * 'a * (int * 'a -> elem * 'a) -> vector
+ val unfoldi: int * 'a * (int * 'a -> elem * 'a) -> vector * 'a
val unsafeSub: vector * int -> elem
val vector: int * elem -> vector
end
Modified: mlton/trunk/basis-library/arrays-and-vectors/sequence.fun
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/sequence.fun 2006-03-30 11:07:48 UTC (rev 4386)
+++ mlton/trunk/basis-library/arrays-and-vectors/sequence.fun 2006-03-30 20:09:58 UTC (rev 4387)
@@ -39,21 +39,21 @@
let
val a = array n
fun loop (i, b) =
- if i >= n
- then ()
+ if i >= n then
+ b
else
let
val (x, b') = f (i, b)
- val _ = Array.update (a, i, x)
+ val () = Array.update (a, i, x)
in
loop (i +? 1, b')
end
- val () = loop (0, b)
+ val b = loop (0, b)
in
- fromArray a
+ (fromArray a, b)
end
- fun tabulate (n, f) = unfoldi (n, (), fn (i, ()) => (f i, ()))
+ fun tabulate (n, f) = #1 (unfoldi (n, (), fn (i, ()) => (f i, ())))
fun new (n, x) = tabulate (n, fn _ => x)
@@ -191,25 +191,26 @@
in loop (min1, min2)
end
fun sequence (sl as T {seq, start, len}): 'a sequence =
- if isMutable orelse (start <> 0 orelse len <> S.length seq)
- then map (fn x => x) sl
- else seq
+ if isMutable orelse (start <> 0 orelse len <> S.length seq) then
+ map (fn x => x) sl
+ else
+ seq
fun append (sl1: 'a slice, sl2: 'a slice): 'a sequence =
- if length sl1 = 0
- then sequence sl2
- else if length sl2 = 0
- then sequence sl1
+ if length sl1 = 0 then
+ sequence sl2
+ else if length sl2 = 0 then
+ sequence sl1
else
let
val l1 = length sl1
val l2 = length sl2
val n = l1 + l2 handle Overflow => raise Size
in
- unfoldi (n, (0, sl1),
- fn (_, (i, sl)) =>
- if i < length sl
- then (unsafeSub (sl, i), (i +? 1, sl))
- else (unsafeSub (sl2, 0), (1, sl2)))
+ #1 (unfoldi (n, (0, sl1),
+ fn (_, (i, sl)) =>
+ if i < length sl then
+ (unsafeSub (sl, i), (i +? 1, sl))
+ else (unsafeSub (sl2, 0), (1, sl2))))
end
fun concat (sls: 'a slice list): 'a sequence =
case sls of
@@ -220,17 +221,19 @@
val n = List.foldl (fn (sl, s) => s + length sl) 0 sls'
handle Overflow => raise Size
in
- unfoldi (n, (0, sl, sls),
- fn (_, ac) =>
- let
- fun loop (i, sl, sls) =
- if i < length sl
- then (unsafeSub (sl, i), (i +? 1, sl, sls))
- else case sls of
- [] => raise Fail "concat bug"
- | sl :: sls => loop (0, sl, sls)
- in loop ac
- end)
+ #1 (unfoldi (n, (0, sl, sls),
+ fn (_, ac) =>
+ let
+ fun loop (i, sl, sls) =
+ if i < length sl then
+ (unsafeSub (sl, i),
+ (i +? 1, sl, sls))
+ else case sls of
+ [] => raise Fail "concat bug"
+ | sl :: sls => loop (0, sl, sls)
+ in
+ loop ac
+ end))
end
fun concatWith (sep: 'a sequence) (sls: 'a slice list): 'a sequence =
let val sep = full sep
Modified: mlton/trunk/basis-library/arrays-and-vectors/sequence.sig
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/sequence.sig 2006-03-30 11:07:48 UTC (rev 4386)
+++ mlton/trunk/basis-library/arrays-and-vectors/sequence.sig 2006-03-30 20:09:58 UTC (rev 4387)
@@ -62,7 +62,7 @@
val duplicate: 'a sequence -> 'a sequence
val new: int * 'a elt -> 'a sequence
val toList: 'a sequence -> 'a elt list
- val unfoldi: int * 'a * (int * 'a -> 'b elt * 'a) -> 'b sequence
+ val unfoldi: int * 'a * (int * 'a -> 'b elt * 'a) -> 'b sequence * 'a
(* Deprecated *)
val checkSlice: 'a sequence * int * int option -> int
Modified: mlton/trunk/basis-library/arrays-and-vectors/vector.sig
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/vector.sig 2006-03-30 11:07:48 UTC (rev 4386)
+++ mlton/trunk/basis-library/arrays-and-vectors/vector.sig 2006-03-30 20:09:58 UTC (rev 4387)
@@ -53,7 +53,7 @@
val duplicate: 'a vector -> 'a vector
val fromArray: 'a array -> 'a vector
val toList: 'a vector -> 'a list
- val unfoldi: int * 'a * (int * 'a -> 'b * 'a) -> 'b vector
+ val unfoldi: int * 'b * (int * 'b -> 'a * 'b) -> 'a vector * 'b
val vector: int * 'a -> 'a vector
(* Deprecated *)
Modified: mlton/trunk/basis-library/mlton/array.sig
===================================================================
--- mlton/trunk/basis-library/mlton/array.sig 2006-03-30 11:07:48 UTC (rev 4386)
+++ mlton/trunk/basis-library/mlton/array.sig 2006-03-30 20:09:58 UTC (rev 4387)
@@ -10,5 +10,5 @@
signature MLTON_ARRAY =
sig
- val unfoldi: int * 'b * (int * 'b -> 'a * 'b) -> 'a array
+ val unfoldi: int * 'b * (int * 'b -> 'a * 'b) -> 'a array * 'b
end
Modified: mlton/trunk/basis-library/mlton/vector.sig
===================================================================
--- mlton/trunk/basis-library/mlton/vector.sig 2006-03-30 11:07:48 UTC (rev 4386)
+++ mlton/trunk/basis-library/mlton/vector.sig 2006-03-30 20:09:58 UTC (rev 4387)
@@ -14,6 +14,6 @@
int * ({sub: int -> 'a, update: int * 'a -> unit}
-> (int -> 'a) * (unit -> unit))
-> 'a vector
- val unfoldi: int * 'b * (int * 'b -> 'a * 'b) -> 'a vector
+ val unfoldi: int * 'b * (int * 'b -> 'a * 'b) -> 'a vector * 'b
end