[MLton-commit] r4355
Matthew Fluet
MLton@mlton.org
Sun, 12 Feb 2006 13:32:30 -0800
Refactoring arrays-and-vectors
----------------------------------------------------------------------
U mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array-slice.sig
U mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array.sig
U mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array.sml
U mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array2.sml
U mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/mono.sml
U mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/sequence.fun
U mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/sequence.sig
U mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/vector-slice.sig
U mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/build/sources.mlb
----------------------------------------------------------------------
Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array-slice.sig
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array-slice.sig 2006-02-12 18:36:59 UTC (rev 4354)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array-slice.sig 2006-02-12 21:32:28 UTC (rev 4355)
@@ -48,8 +48,15 @@
val concat: 'a slice list -> 'a array
val toList: 'a slice -> 'a list
+ val slice': 'a array * SeqIndex.int * SeqIndex.int option -> 'a slice
+ val unsafeSlice': 'a array * SeqIndex.int * SeqIndex.int option -> 'a slice
val unsafeSlice: 'a array * int * int option -> 'a slice
+ val sub': 'a slice * SeqIndex.int -> 'a
+ val unsafeSub': 'a slice * SeqIndex.int -> 'a
val unsafeSub: 'a slice * int -> 'a
+ val unsafeSubslice': 'a slice * SeqIndex.int * SeqIndex.int option -> 'a slice
val unsafeSubslice: 'a slice * int * int option -> 'a slice
+ val update': 'a slice * SeqIndex.int * 'a -> unit
+ val unsafeUpdate': 'a slice * SeqIndex.int * 'a -> unit
val unsafeUpdate: 'a slice * int * 'a -> unit
end
Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array.sig
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array.sig 2006-02-12 18:36:59 UTC (rev 4354)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array.sig 2006-02-12 21:32:28 UTC (rev 4355)
@@ -40,7 +40,12 @@
structure ArraySlice: ARRAY_SLICE_EXTRA
+ val arrayUninit': SeqIndex.int -> 'a array
+ val arrayUninit: int -> 'a array
+ val array': SeqIndex.int * 'a -> 'a array
+ val unsafeSub': 'a array * SeqIndex.int -> 'a
val unsafeSub: 'a array * int -> 'a
+ val unsafeUpdate': 'a array * SeqIndex.int * 'a -> unit
val unsafeUpdate: 'a array * int * 'a -> unit
val concat: 'a array list -> 'a array
Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array.sml 2006-02-12 18:36:59 UTC (rev 4354)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array.sml 2006-02-12 21:32:28 UTC (rev 4355)
@@ -69,8 +69,6 @@
end
end
- val array = new
-
local
fun make f arr = f (ArraySlice.full arr)
in
@@ -84,7 +82,14 @@
dst = dst, di = di}
end
+ val arrayUninit' = newUninit'
+ val arrayUninit = newUninit
+ val array' = new'
+ val array = new
+
+ fun update' (arr, i, x) = updateMk' Primitive.Array.updateUnsafe (arr, i, x)
fun update (arr, i, x) = updateMk Primitive.Array.updateUnsafe (arr, i, x)
+ fun unsafeUpdate' (arr, i, x) = unsafeUpdateMk' Primitive.Array.updateUnsafe (arr, i, x)
fun unsafeUpdate (arr, i, x) = unsafeUpdateMk Primitive.Array.updateUnsafe (arr, i, x)
end
structure ArraySlice: ARRAY_SLICE_EXTRA = Array.ArraySlice
Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array2.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array2.sml 2006-02-12 18:36:59 UTC (rev 4354)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/array2.sml 2006-02-12 21:32:28 UTC (rev 4355)
@@ -6,68 +6,183 @@
* See the file MLton-LICENSE for details.
*)
-structure Array2: ARRAY2 =
+structure Array2 (* : ARRAY2 *) =
struct
- open Primitive.Int
- (* I am careful to use a type here instead of a datatype so that
- * 'a array will be an equality type irrespective of whether 'a is.
- * This is probably just an NJ-ism, but I don't want to think about it.
- *)
- type 'a array = {rows: int,
- cols: int,
- array: 'a Array.array}
+ val op +? = SeqIndex.+?
+ val op + = SeqIndex.+
+ val op -? = SeqIndex.-?
+ val op - = SeqIndex.-
+ val op *? = SeqIndex.*?
+ val op * = SeqIndex.*
+ val op < = SeqIndex.<
+ val op <= = SeqIndex.<=
+ val op > = SeqIndex.>
+ val op >= = SeqIndex.>=
+ val ltu = SeqIndex.ltu
+ val leu = SeqIndex.leu
+ val gtu = SeqIndex.gtu
+ val geu = SeqIndex.geu
- fun dimensions ({rows, cols, ...}: 'a array) = (rows, cols)
- fun nRows ({rows, ...}: 'a array) = rows
- fun nCols ({cols, ...}: 'a array) = cols
+ type 'a array = {array: 'a Array.array,
+ rows: SeqIndex.int,
+ cols: SeqIndex.int}
+ fun dimensions' ({rows, cols, ...}: 'a array) = (rows, cols)
+ fun dimensions ({rows, cols, ...}: 'a array) =
+ (SeqIndex.toIntUnsafe rows, SeqIndex.toIntUnsafe cols)
+ fun nRows' ({rows, ...}: 'a array) = rows
+ fun nRows ({rows, ...}: 'a array) = SeqIndex.toIntUnsafe rows
+ fun nCols' ({cols, ...}: 'a array) = cols
+ fun nCols ({cols, ...}: 'a array) = SeqIndex.toIntUnsafe cols
+
type 'a region = {base: 'a array,
row: int,
col: int,
nrows: int option,
ncols: int option}
- fun checkRegion {base, row, col, nrows, ncols} =
- let val (rows, cols) = dimensions base
- in {stopRow = Array.checkSliceMax (row, nrows, rows),
- stopCol = Array.checkSliceMax (col, ncols, cols)}
- end
-
- fun wholeRegion (a: 'a array): 'a region =
+ local
+ fun checkSliceMax' (start: int,
+ num: SeqIndex.int option,
+ max: SeqIndex.int): SeqIndex.int * SeqIndex.int =
+ case num of
+ NONE => if Primitive.Controls.safe
+ then let
+ val start =
+ (SeqIndex.fromInt start)
+ handle Overflow => raise Subscript
+ in
+ if gtu (start, max)
+ then raise Subscript
+ else (start, max)
+ end
+ else (SeqIndex.fromIntUnsafe start, max)
+ | SOME num => if Primitive.Controls.safe
+ then let
+ val start =
+ (SeqIndex.fromInt start)
+ handle Overflow => raise Subscript
+ in
+ if (start < 0 orelse num < 0
+ orelse start +? num > max)
+ then raise Subscript
+ else (start, start +? num)
+ end
+ else (SeqIndex.fromIntUnsafe start,
+ SeqIndex.fromIntUnsafe start +? num)
+ fun checkSliceMax (start: int,
+ num: int option,
+ max: SeqIndex.int): SeqIndex.int * SeqIndex.int =
+ if Primitive.Controls.safe
+ then (checkSliceMax' (start, Option.map SeqIndex.fromInt num, max))
+ handle Overflow => raise Subscript
+ else checkSliceMax' (start, Option.map SeqIndex.fromIntUnsafe num, max)
+ in
+ fun checkRegion' {base, row, col, nrows, ncols} =
+ let
+ val (rows, cols) = dimensions' base
+ val (startRow, stopRow) = checkSliceMax' (row, nrows, rows)
+ val (startCol, stopCol) = checkSliceMax' (col, ncols, cols)
+ in
+ {startRow = startRow, stopRow = stopRow,
+ startCol = startCol, stopCol = stopCol}
+ end
+ fun checkRegion {base, row, col, nrows, ncols} =
+ let
+ val (rows, cols) = dimensions' base
+ val (startRow, stopRow) = checkSliceMax (row, nrows, rows)
+ val (startCol, stopCol) = checkSliceMax (col, ncols, cols)
+ in
+ {startRow = startRow, stopRow = stopRow,
+ startCol = startCol, stopCol = stopCol}
+ end
+ end
+
+ fun wholeRegion (a as {rows, cols, ...}: 'a array): 'a region =
{base = a, row = 0, col = 0, nrows = NONE, ncols = NONE}
datatype traversal = RowMajor | ColMajor
local
fun make (rows, cols, doit) =
- if Primitive.safe andalso (rows < 0 orelse cols < 0)
+ if Primitive.Controls.safe
+ andalso (rows < 0 orelse cols < 0)
then raise Size
- else {rows = rows,
- cols = cols,
- array = doit (rows * cols handle Overflow => raise Size)}
+ else {array = doit (rows * cols handle Overflow => raise Size),
+ rows = rows,
+ cols = cols}
in
+ fun arrayUninit' (rows, cols) =
+ make (rows, cols, Array.arrayUninit')
+ fun array' (rows, cols, init) =
+ make (rows, cols, fn size => Array.array' (size, init))
+ end
+ local
+ fun make (rows, cols, doit) =
+ if Primitive.Controls.safe
+ then let
+ val rows =
+ (SeqIndex.fromInt rows)
+ handle Overflow => raise Size
+ val cols =
+ (SeqIndex.fromInt cols)
+ handle Overflow => raise Size
+ in
+ doit (rows, cols)
+ end
+ else doit (SeqIndex.fromIntUnsafe rows,
+ SeqIndex.fromIntUnsafe cols)
+ in
fun arrayUninit (rows, cols) =
- make (rows, cols, Primitive.Array.array)
+ make (rows, cols, fn (rows, cols) => arrayUninit' (rows, cols))
fun array (rows, cols, init) =
- make (rows, cols, fn size => Array.array (size, init))
+ make (rows, cols, fn (rows, cols) => array' (rows, cols, init))
end
fun array0 (): 'a array =
- {rows = 0,
- cols = 0,
- array = Primitive.Array.array 0}
+ {array = Array.arrayUninit' 0,
+ rows = 0,
+ cols = 0}
- fun spot ({rows, cols, ...}: 'a array, r, c) =
- if Primitive.safe andalso (geu (r, rows) orelse geu (c, cols))
+ fun unsafeSpot' (a as {cols, ...}: 'a array, r, c) =
+ r *? cols +? c
+ fun spot' (a as {rows, cols, ...}: 'a array, r, c) =
+ if Primitive.Controls.safe
+ andalso (geu (r, rows) orelse geu (c, cols))
then raise Subscript
- else r *? cols +? c
+ else unsafeSpot' (a, r, c)
- fun sub (a as {array, ...}: 'a array, r, c) =
- Primitive.Array.sub (array, spot (a, r, c))
+ fun unsafeSub' (a as {array, ...}: 'a array, r, c) =
+ Array.unsafeSub' (array, unsafeSpot' (a, r, c))
+ fun sub' (a as {array, ...}: 'a array, r, c) =
+ Array.unsafeSub' (array, spot' (a, r, c))
+ fun unsafeUpdate' (a as {array, ...}: 'a array, r, c, x) =
+ Array.unsafeUpdate' (array, unsafeSpot' (a, r, c), x)
+ fun update' (a as {array, ...}: 'a array, r, c, x) =
+ Array.unsafeUpdate' (array, spot' (a, r, c), x)
- fun update (a as {array, ...}: 'a array, r, c, x) =
- Primitive.Array.update (array, spot (a, r, c), x)
+ local
+ fun make (r, c, doit) =
+ if Primitive.Controls.safe
+ then let
+ val r =
+ (SeqIndex.fromInt r)
+ handle Overflow => raise Subscript
+ val c =
+ (SeqIndex.fromInt c)
+ handle Overflow => raise Subscript
+ in
+ doit (r, c)
+ end
+ else doit (SeqIndex.fromIntUnsafe r,
+ SeqIndex.fromIntUnsafe c)
+ in
+ fun sub (a, r, c) =
+ make (r, c, fn (r, c) => sub' (a, r, c))
+ fun update (a, r, c, x) =
+ make (r, c, fn (r, c) => update' (a, r, c, x))
+ end
fun 'a fromList (rows: 'a list list): 'a array =
case rows of
@@ -75,18 +190,19 @@
| row1 :: _ =>
let
val cols = length row1
- val a as {array, ...} = arrayUninit (length rows, cols)
+ val a as {array, rows = rows', cols = cols', ...} =
+ arrayUninit (length rows, cols)
val _ =
List.foldl
(fn (row: 'a list, i) =>
let
- val max = i +? cols
+ val max = i +? cols'
val i' =
List.foldl (fn (x: 'a, i) =>
(if i >= max
then raise Size
- else (Primitive.Array.update (array, i, x)
- ; i + 1)))
+ else (Array.unsafeUpdate' (array, i, x)
+ ; i +? 1)))
i row
in if i' = max
then i'
@@ -97,37 +213,77 @@
a
end
- fun row ({rows, cols, array}, r) =
- if Primitive.safe andalso geu (r, rows)
+ fun row' ({array, rows, cols}, r) =
+ if Primitive.Controls.safe andalso geu (r, rows)
then raise Subscript
else
- ArraySlice.vector (ArraySlice.slice (array, r *? cols, SOME cols))
-
- fun column (a as {rows, cols, ...}: 'a array, c) =
- if Primitive.safe andalso geu (c, cols)
+ ArraySlice.vector (ArraySlice.slice' (array, r *? cols, SOME cols))
+ fun row (a, r) =
+ if Primitive.Controls.safe
+ then let
+ val r =
+ (SeqIndex.fromInt r)
+ handle Overflow => raise Subscript
+ in
+ row' (a, r)
+ end
+ else row' (a, SeqIndex.fromIntUnsafe r)
+ fun column' (a as {rows, cols, ...}: 'a array, c) =
+ if Primitive.Controls.safe andalso geu (c, cols)
then raise Subscript
else
- Vector.tabulate (rows, fn r => sub(a, r, c))
+ Vector.tabulate' (rows, fn r => unsafeSub' (a, r, c))
+ fun column (a, c) =
+ if Primitive.Controls.safe
+ then let
+ val c =
+ (SeqIndex.fromInt c)
+ handle Overflow => raise Subscript
+ in
+ column' (a, c)
+ end
+ else column' (a, SeqIndex.fromIntUnsafe c)
- fun foldi trv f b (region as {base, row, col, ...}) =
+ fun foldi' trv f b (region as {base, row, col, ...}) =
let
- val {stopRow, stopCol} = checkRegion region
+ val {startRow, stopRow, startCol, stopCol} = checkRegion region
in
case trv of
RowMajor =>
- Util.naturalFoldStartStop
- (row, stopRow, b, fn (r, b) =>
- Util.naturalFoldStartStop
- (col, stopCol, b, fn (c, b) =>
- f (r, c, sub (base, r, c), b)))
+ let
+ fun loopRow (r, b) =
+ if r >= stopRow then b
+ else let
+ fun loopCol (c, b) =
+ if c >= stopCol then b
+ else loopCol (c +? 1, f (r, c, sub' (base, r, c), b))
+ in
+ loopRow (r +? 1, loopCol (startCol, b))
+ end
+ in
+ loopRow (startRow, b)
+ end
| ColMajor =>
- Util.naturalFoldStartStop
- (col, stopCol, b, fn (c, b) =>
- Util.naturalFoldStartStop
- (row, stopRow, b, fn (r, b) =>
- f (r, c, sub (base, r, c), b)))
+ let
+ fun loopCol (c, b) =
+ if c >= stopCol then b
+ else let
+ fun loopRow (r, b) =
+ if r >= stopRow then b
+ else loopRow (r +? 1, f (r, c, sub' (base, r, c), b))
+ in
+ loopCol (c +? 1, loopRow (startRow, b))
+ end
+ in
+ loopCol (startCol, b)
+ end
end
+ fun foldi trv f b a =
+ foldi' trv (fn (r, c, x, b) =>
+ f (SeqIndex.toIntUnsafe r,
+ SeqIndex.toIntUnsafe c,
+ x, b)) b a
fun fold trv f b a =
foldi trv (fn (_, _, x, b) => f (x, b)) b (wholeRegion a)
@@ -142,6 +298,7 @@
fun modify trv f a = modifyi trv (f o #3) (wholeRegion a)
fun tabulate trv (rows, cols, f) =
+(*
if !Primitive.usesCallcc
then
(* All this mess is careful to construct a list representing
@@ -204,20 +361,23 @@
; {rows = rows, cols = cols, array = a}
end
else
+*)
let val a = arrayUninit (rows, cols)
in modifyi trv (fn (r, c, _) => f (r, c)) (wholeRegion a)
; a
end
- fun copy {src = src as {base, row, col, ...}: 'a region,
+ fun copy {src = src as {base, ...}: 'a region,
dst, dst_row, dst_col} =
let
- val {stopRow, stopCol} = checkRegion src
- val nrows = stopRow -? row
- val ncols = stopCol -? col
- val _ = checkRegion {base = dst, row = dst_row, col = dst_col,
- nrows = SOME nrows, ncols = SOME ncols}
- fun for (start, stop, f: int -> unit) =
+ val {startRow, stopRow, startCol, stopCol} = checkRegion src
+ val nrows = stopRow -? startRow
+ val ncols = stopCol -? startCol
+ val {startRow = dst_row, startCol = dst_col, ...} =
+ checkRegion' {base = dst, row = dst_row, col = dst_col,
+ nrows = SOME nrows,
+ ncols = SOME ncols}
+ fun forUp (start, stop, f: SeqIndex.int -> unit) =
let
fun loop i =
if i >= stop
@@ -225,7 +385,7 @@
else (f i; loop (i + 1))
in loop start
end
- fun forDown (start, stop, f: int -> unit) =
+ fun forDown (start, stop, f: SeqIndex.int -> unit) =
let
fun loop i =
if i < start
@@ -233,11 +393,11 @@
else (f i; loop (i - 1))
in loop (stop -? 1)
end
- val forRows = if row <= dst_row then forDown else for
- val forCols = if col <= dst_col then for else forDown
+ val forRows = if startRow <= dst_row then forDown else forUp
+ val forCols = if startCol <= dst_col then forUp else forDown
in forRows (0, nrows, fn r =>
- forCols (0, ncols, fn c =>
- update (dst, dst_row +? r, dst_col +? c,
- sub (base, row +? r, col +? c))))
+ forCols (0, ncols, fn c =>
+ unsafeUpdate' (dst, dst_row +? r, dst_col +? c,
+ unsafeSub' (base, startRow +? r, startCol +? c))))
end
end
Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/mono.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/mono.sml 2006-02-12 18:36:59 UTC (rev 4354)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/mono.sml 2006-02-12 21:32:28 UTC (rev 4355)
@@ -44,7 +44,7 @@
end
local
- structure S = EqMono (type elem = Bool.bool)
+ structure S = EqMono (type elem = Primitive.Bool.bool)
open S
in
structure BoolVector = Vector
@@ -54,24 +54,9 @@
structure BoolArray2 = Array2
end
local
- structure S:>
- EQ_MONO
- where type Array.elem = char
- where type Vector.vector = string
- = EqMono (type elem = char)
+ structure S = EqMono (type elem = Primitive.Int8.int)
open S
in
- structure CharArray = Array
- structure CharArray2 = Array2
- structure CharArraySlice = ArraySlice
- structure CharVector = Vector
- structure CharVectorSlice = VectorSlice
- val _ = CharVector.fromArray: CharArray.array -> CharVector.vector
-end
-local
- structure S = EqMono (type elem = Int8.int)
- open S
-in
structure Int8Vector = Vector
structure Int8VectorSlice = VectorSlice
structure Int8Array = Array
@@ -79,7 +64,7 @@
structure Int8Array2 = Array2
end
local
- structure S = EqMono (type elem = Int16.int)
+ structure S = EqMono (type elem = Primitive.Int16.int)
open S
in
structure Int16Vector = Vector
@@ -89,7 +74,7 @@
structure Int16Array2 = Array2
end
local
- structure S = EqMono (type elem = Int32.int)
+ structure S = EqMono (type elem = Primitive.Int32.int)
open S
in
structure Int32Vector = Vector
@@ -99,7 +84,7 @@
structure Int32Array2 = Array2
end
local
- structure S = EqMono (type elem = Int64.int)
+ structure S = EqMono (type elem = Primitive.Int64.int)
open S
in
structure Int64Vector = Vector
@@ -109,7 +94,7 @@
structure Int64Array2 = Array2
end
local
- structure S = EqMono (type elem = IntInf.int)
+ structure S = EqMono (type elem = Primitive.IntInf.int)
open S
in
structure IntInfVector = Vector
@@ -119,7 +104,7 @@
structure IntInfArray2 = Array2
end
local
- structure S = Mono (type elem = Real32.real)
+ structure S = Mono (type elem = Primitive.Real32.real)
open S
in
structure Real32Vector = Vector
@@ -129,7 +114,7 @@
structure Real32Array2 = Array2
end
local
- structure S = Mono (type elem = Real64.real)
+ structure S = Mono (type elem = Primitive.Real64.real)
open S
in
structure Real64Vector = Vector
@@ -139,10 +124,7 @@
structure Real64Array2 = Array2
end
local
- structure S:>
- EQ_MONO
- where type Array.elem = Word8.word
- = EqMono (type elem = Word8.word)
+ structure S = EqMono (type elem = Primitive.Word8.word)
open S
in
structure Word8Vector = Vector
@@ -152,7 +134,7 @@
structure Word8Array2 = Array2
end
local
- structure S = EqMono (type elem = Word16.word)
+ structure S = EqMono (type elem = Primitive.Word16.word)
open S
in
structure Word16Vector = Vector
@@ -162,7 +144,7 @@
structure Word16Array2 = Array2
end
local
- structure S = EqMono (type elem = Word32.word)
+ structure S = EqMono (type elem = Primitive.Word32.word)
open S
in
structure Word32Vector = Vector
@@ -172,7 +154,7 @@
structure Word32Array2 = Array2
end
local
- structure S = EqMono (type elem = Word64.word)
+ structure S = EqMono (type elem = Primitive.Word64.word)
open S
in
structure Word64Vector = Vector
@@ -182,38 +164,74 @@
structure Word64Array2 = Array2
end
-structure IntVector = Int32Vector
-structure IntVectorSlice = Int32VectorSlice
-structure IntArray = Int32Array
-structure IntArraySlice = Int32ArraySlice
-structure IntArray2 = Int32Array2
-structure LargeIntVector = IntInfVector
-structure LargeIntVectorSlice = IntInfVectorSlice
-structure LargeIntArray = IntInfArray
-structure LargeIntArraySlice = IntInfArraySlice
-structure LargeIntArray2 = IntInfArray2
-
-structure RealVector = Real64Vector
-structure RealVectorSlice = Real64VectorSlice
-structure RealArray = Real64Array
-structure RealArraySlice = Real64ArraySlice
-structure RealArray2 = Real64Array2
-
-structure LargeRealVector = Real64Vector
-structure LargeRealVectorSlice = Real64VectorSlice
-structure LargeRealArray = Real64Array
-structure LargeRealArraySlice = Real64ArraySlice
-structure LargeRealArray2 = Real64Array2
-
-structure WordVector = Word32Vector
-structure WordVectorSlice = Word32VectorSlice
-structure WordArray = Word32Array
-structure WordArraySlice = Word32ArraySlice
-structure WordArray2 = Word32Array2
-
-structure LargeWordVector = Word64Vector
-structure LargeWordVectorSlice = Word64VectorSlice
-structure LargeWordArray = Word64Array
-structure LargeWordArraySlice = Word64ArraySlice
-structure LargeWordArray2 = Word64Array2
+local
+ structure S = EqMono (type elem = Char.char)
+ open S
+in
+ structure CharArray = Array
+ structure CharArray2 = Array2
+ structure CharArraySlice = ArraySlice
+ structure CharVector = Vector
+ structure CharVectorSlice = VectorSlice
+end
+local
+ structure S = EqMono (type elem = Int.int)
+ open S
+in
+ structure IntVector = Vector
+ structure IntVectorSlice = VectorSlice
+ structure IntArray = Array
+ structure IntArraySlice = ArraySlice
+ structure IntArray2 = Array2
+end
+local
+ structure S = EqMono (type elem = LargeInt.int)
+ open S
+in
+ structure LargeIntVector = Vector
+ structure LargeIntVectorSlice = VectorSlice
+ structure LargeIntArray = Array
+ structure LargeIntArraySlice = ArraySlice
+ structure LargeIntArray2 = Array2
+end
+local
+ structure S = Mono (type elem = Real.real)
+ open S
+in
+ structure RealVector = Vector
+ structure RealVectorSlice = VectorSlice
+ structure RealArray = Array
+ structure RealArraySlice = ArraySlice
+ structure RealArray2 = Array2
+end
+local
+ structure S = Mono (type elem = LargeReal.real)
+ open S
+in
+ structure LargeRealVector = Vector
+ structure LargeRealVectorSlice = VectorSlice
+ structure LargeRealArray = Array
+ structure LargeRealArraySlice = ArraySlice
+ structure LargeRealArray2 = Array2
+end
+local
+ structure S = EqMono (type elem = Word.word)
+ open S
+in
+ structure WordVector = Vector
+ structure WordVectorSlice = VectorSlice
+ structure WordArray = Array
+ structure WordArraySlice = ArraySlice
+ structure WordArray2 = Array2
+end
+local
+ structure S = EqMono (type elem = LargeWord.word)
+ open S
+in
+ structure LargeWordVector = Vector
+ structure LargeWordVectorSlice = VectorSlice
+ structure LargeWordArray = Array
+ structure LargeWordArraySlice = ArraySlice
+ structure LargeWordArray2 = Array2
+end
Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/sequence.fun
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/sequence.fun 2006-02-12 18:36:59 UTC (rev 4354)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/sequence.fun 2006-02-12 21:32:28 UTC (rev 4355)
@@ -76,20 +76,23 @@
handle Overflow => raise Fail "Sequence.length"
else SeqIndex.toIntUnsafe (length' s)
- fun array' n =
+ fun arrayUninit' n =
if not S.isMutable andalso n = 0
then Array.array0Const ()
else if Primitive.Controls.safe
andalso (n < 0 orelse n > maxLen')
then raise Size
else Array.arrayUnsafe n
- fun array n = array' (fromIntForLength n)
+ fun arrayUninit n = arrayUninit' (fromIntForLength n)
- fun seq0 () = S.fromArray (array' 0)
+ fun newUninit' n = S.fromArray (arrayUninit' n)
+ fun newUninit n = S.fromArray (arrayUninit n)
+ fun seq0 () = S.fromArray (arrayUninit' 0)
+
fun unfoldi' (n, b, f) =
let
- val a = array' n
+ val a = arrayUninit' n
fun loop (i, b) =
if i >= n
then ()
@@ -112,11 +115,12 @@
fun tabulate (n, f) =
unfoldi (n, (), fn (i, ()) => (f i, ()))
+ fun new' (n, x) = tabulate' (n, fn _ => x)
fun new (n, x) = tabulate (n, fn _ => x)
fun fromList l =
let
- val a = array (List.length l)
+ val a = arrayUninit (List.length l)
val _ =
List.foldl (fn (x, i) => (Array.updateUnsafe (a, i, x) ; (i +? 1))) 0 l
in
Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/sequence.sig
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/sequence.sig 2006-02-12 18:36:59 UTC (rev 4354)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/sequence.sig 2006-02-12 21:32:28 UTC (rev 4355)
@@ -80,6 +80,9 @@
val create: (SeqIndex.int * (SeqIndex.int -> 'b elt) -> 'c) ->
('a elt -> 'b elt) -> 'a sequence -> 'c
val duplicate: 'a sequence -> 'a sequence
+ val newUninit': SeqIndex.int -> 'a sequence
+ val newUninit: int -> 'a sequence
+ val new': SeqIndex.int * 'a elt -> 'a sequence
val new: int * 'a elt -> 'a sequence
val toList: 'a sequence -> 'a elt list
val unfoldi': SeqIndex.int * 'a * (SeqIndex.int * 'a -> 'b elt * 'a) -> 'b sequence
Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/vector-slice.sig
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/vector-slice.sig 2006-02-12 18:36:59 UTC (rev 4354)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/vector-slice.sig 2006-02-12 21:32:28 UTC (rev 4355)
@@ -26,10 +26,10 @@
val appi: (int * 'a -> unit) -> 'a slice -> unit
val app: ('a -> unit) -> 'a slice -> unit
val mapi: (int * 'a -> 'b) -> 'a slice -> 'b Vector.vector
- val map: ('a -> 'b) -> 'a slice -> 'b Vector.vector
+ val map: ('a -> 'b) -> 'a slice -> 'b Vector.vector
val foldli: (int * 'a * 'b -> 'b) -> 'b -> 'a slice -> 'b
+ val foldl: ('a * 'b -> 'b) -> 'b -> 'a slice -> 'b
val foldri: (int * 'a * 'b -> 'b) -> 'b -> 'a slice -> 'b
- val foldl: ('a * 'b -> 'b) -> 'b -> 'a slice -> 'b
val foldr: ('a * 'b -> 'b) -> 'b -> 'a slice -> 'b
val findi: (int * 'a -> bool) -> 'a slice -> (int * 'a) option
val find: ('a -> bool) -> 'a slice -> 'a option
Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/build/sources.mlb
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/build/sources.mlb 2006-02-12 18:36:59 UTC (rev 4354)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/build/sources.mlb 2006-02-12 21:32:28 UTC (rev 4355)
@@ -71,19 +71,17 @@
../arrays-and-vectors/array.sig
../arrays-and-vectors/array.sml
../arrays-and-vectors/array2.sig
-(*
../arrays-and-vectors/array2.sml
-*)
../arrays-and-vectors/mono-vector-slice.sig
../arrays-and-vectors/mono-vector.sig
../arrays-and-vectors/mono-vector.fun
../arrays-and-vectors/mono-array-slice.sig
../arrays-and-vectors/mono-array.sig
../arrays-and-vectors/mono-array.fun
-(*
../arrays-and-vectors/mono-array2.sig
../arrays-and-vectors/mono-array2.fun
../arrays-and-vectors/mono.sml
+(*
../../text/string0.sml
../../text/char0.sml
../../misc/reader.sig