Array2 structure
The Array2 structure provides polymorphic mutable 2-dimensional arrays. Arrays also have a special equality property: two arrays are equal  if they are the same array, i.e., created by the same call to a primitive array constructor such as array, fromList, etc.;  otherwise they are not equal. This also holds for arrays of zero length. Thus, type t array admits equality even if ty does not. 
signature ARRAY2
structure Array2 : ARRAY2
eqtype 'a array
type 'a region = {base : 'a array, row : int, col : int, nrows : int option, ncols : int option}       
datatype traversal
  = RowMajor
  | ColMajor
val array : (int * int * 'a) -> 'a array         
val fromList : 'a list list -> 'a array         
val tabulate : traversal -> (int * int * ((int * int) -> 'a)) -> 'a array         
val sub : ('a array * int * int) -> 'a         
val update : ('a array * int * int * 'a) -> unit         
val dimensions : 'a array -> (int * int)       
val nCols : 'a array -> int       
val nRows : 'a array -> int         
val row : ('a array * int) -> 'a Vector.vector         
val column : ('a array * int) -> 'a Vector.vector         
val copy : {src : 'a region, dst : 'a array, dst_row : int, dst_col : int} -> unit         
val appi : traversal -> ((int * int * 'a) -> unit) -> 'a region -> unit         
val app : traversal -> ('a -> unit) -> 'a array -> unit         
val modifyi : traversal -> ((int * int * 'a) -> 'a) -> 'a region -> unit         
val modify : traversal -> ('a -> 'a) -> 'a array -> unit         
val foldi : traversal -> ((int * int * 'a * 'b) -> 'b) -> 'b -> 'a region -> 'b         
val fold : traversal -> (('a * 'b) -> 'b) -> 'b -> 'a array -> 'b         
eqtype 'a array
type 'a region
ncols = SOME w,       the region includes only those elements in columns with indices  in the range       col + (w - 1) (inclusive). If       ncols = NONE, the region includes only those elements lying on or to the right of column col. A similar interpretation holds for the row and nrows fields. Thus, the region corresponds to all those elements with position (i,j) such that i lies in the specified range of rows and j lies in  the specified range of columns. If arr is an array, with dimensions arr = (rows,cols), then a region is said to be valid with respect to arr if 
0 <= row <= row+nr <= rowsand
0 <= col <= col+nc <= colswhere nr and nc are the number of rows and columns, respectively, of the region.
datatype traversal
array (r, c, init)
          
fromList l
          
hd l           gives the first row, hd (tl l) gives the second row, etc.           Raises the Size exception if the           the resulting array would be too large           or if the lists in l do not all have the same length.     
tabulate trv (r, c, f)
          
f (i,j).       The elements are initialized in the traversal order specified by       trv. 	  If r < 0, c < 0 or       the resulting array would be too large,       the Size exception is raised.     
sub (arr, i, j)
          
nRows arr <= i or       nCols arr <= j, then 	  the Subscript exception is raised.     
update (arr, i, j, a)
          
nRows arr <= i or       nCols arr <= j, then 	  the Subscript exception is raised.     
dimensions arr
          
          nCols arr
          
          nRows arr
          
nCols returns           the number of columns, nRows returns the number of rows           and dimension returns a pair containing the number of rows           and the number of columns           of arr. The functions nRows and nCols are           respectively equivalent to #1 o dimensions            and #2 o dimensions     
row (arr, i)
          
nRows arr <= i.     
column (arr, j)
          
nCols arr <= j.     
copy {src, dst, dst_row, dst_col}
          
#row src,#col src)th element being copied to           position (dst_row,dst_col) in the destination array. 	  If the source region is not valid, 	  then the Subscript exception is raised.       Similarly, if the derived destination region (the source region       src translated to (dst_row,dst_col))       is not valid in dst, 	  then the Subscript exception is raised.           
Implementation note:
The
copyfunction must correctly handle the case in which src and dst are equal, and the source and destination regions overlap.
appi tr f reg
          
          app tr f arr
          
	  The function app applies f to the whole array and 	  does not supply the element index to f. 	  Thus the expression app tr f arr 	  is equivalent to: 	  
	    appi tr (f o #3) {base=arr, row=0, col=0, nrows=NONE, ncols=NONE}
	  
     
modifyi tr f reg
          
          modify tr f arr
          
	  The function modify applies f to the whole array and 	  does not supply the element index to f. 	  Thus the expression modify tr f arr 	  is equivalent to: 	  
	    modifyi tr (f o #3) {base=arr, row=0, col=0, nrows=NONE, ncols=NONE}
	  
     
foldi tr f init reg
          
          fold tr f init arr
          
	  The function fold applies f to the whole array and 	  does not supply the element index to f. 	  Thus the expression fold tr f init arr 	  is equivalent to: 	  
	    foldi tr (fn (_,_,a,b) => f (a,b)) init {base=arr, row=0, col=0, nrows=NONE, ncols=NONE}
	  
   
Array, MONO_ARRAY2
Last Modified April 11, 1997
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies