home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / Vector.sig < prev    next >
Encoding:
Text File  |  1996-07-03  |  4.5 KB  |  109 lines  |  [TEXT/R*ch]

  1. (* Vector.sig -- SML Standard Library *)
  2.  
  3. type 'a vector = 'a vector
  4. val maxLen   : int
  5.  
  6. val fromList : 'a list -> 'a vector
  7. val tabulate : int * (int -> 'a) -> 'a vector
  8.  
  9. val length   : 'a vector -> int
  10. val sub      : 'a vector * int -> 'a
  11. val extract  : 'a vector * int * int option -> 'a vector
  12. val concat   : 'a vector list -> 'a vector
  13.  
  14. val app      : ('a -> unit) -> 'a vector -> unit
  15. val foldl    : ('a * 'b -> 'b) -> 'b -> 'a vector -> 'b
  16. val foldr    : ('a * 'b -> 'b) -> 'b -> 'a vector -> 'b
  17.  
  18. val appi     : (int * 'a -> unit) -> 'a vector * int * int option -> unit
  19. val foldli   : (int * 'a * 'b -> 'b) -> 'b -> 'a vector*int*int option -> 'b
  20. val foldri   : (int * 'a * 'b -> 'b) -> 'b -> 'a vector*int*int option -> 'b
  21.  
  22. (* Type [ty vector] is the type of one-dimensional, immutable,
  23.    zero-based constant-time-access vectors with elements of type ty.
  24.    Type ty vector admits equality if ty does.  Vectors v1 and v2
  25.    are equal if they have the same length and their elements are equal.
  26.  
  27.    [maxLen] is the maximal number of elements in a vector.
  28.  
  29.    [fromList xs] returns a vector whose elements are those of xs.
  30.    Raises Size if length xs > maxLen.
  31.  
  32.    [tabulate(n, f)] returns a vector of length n whose elements
  33.    are f 0, f 1, ..., f (n-1), created from left to right.  Raises
  34.    Size if n<0 or n>maxLen.
  35.  
  36.    [length v] returns the number of elements in v.
  37.  
  38.    [sub(v, i)] returns the i'th element of v, counting from 0.
  39.    Raises Subscript if i<0 or i>=length v.
  40.  
  41.    [extract(v, i, NONE)] returns a vector of the elements v[i..length v-1]
  42.    of v.  Raises Subscript if i<0 or i>length v.
  43.  
  44.    [extract(v, i, SOME n)] returns a vector of the elements v[i..i+n-1]
  45.    of v.  Raises Subscript if i<0 or n<0 or i+n>length v.
  46.  
  47.    [concat vs] returns a vector which is the concatenation from left
  48.    to right og the vectors in vs.  Raises Size if the sum of the
  49.    sizes of the vectors in vs is larger than maxLen.
  50.  
  51.    [foldl f e v] folds function f over v from left to right.  That is,
  52.    computes f(v[len-1], f(v[len-2], ..., f(v[1], f(v[0], e)) ...)),
  53.    where len is the length of v.
  54.  
  55.    [foldr f e v] folds function f over v from right to left.  That is,
  56.    computes f(v[0], f(v[1], ..., f(v[len-2], f(v[len-1], e)) ...)),
  57.    where len is the length of v.
  58.  
  59.    [app f v] applies f to v[j] for j=0,1,...,length v-1.
  60.  
  61.  
  62.    The following iterators generalize the above ones in two ways:
  63.  
  64.     . the index j is also being passed to the function being iterated;
  65.     . the iterators work on a slice (subvector) of a vector.
  66.  
  67.    The slice (v, i, SOME n) denotes the subvector v[i..i+n-1].  That is,
  68.    v[i] is the first element of the slice, and n is the length of the
  69.    slice.  Valid only if 0 <= i <= i+n <= length v.
  70.  
  71.    The slice (v, i, NONE) denotes the subvector v[i..length v-1].  That
  72.    is, the slice denotes the suffix of the vector starting at i.  Valid
  73.    only if 0 <= i <= length v.  Equivalent to (v, i, SOME(length v - i)).
  74.  
  75.        slice             meaning 
  76.        ----------------------------------------------------------
  77.        (v, 0, NONE)      the whole vector             v[0..len-1]   
  78.        (v, 0, SOME n)    a left subvector (prefix)    v[0..n-1]
  79.        (v, i, NONE)      a right subvector (suffix)   v[i..len-1]
  80.        (v, i, SOME n)    a general slice              v[i..i+n-1] 
  81.  
  82.    [foldli f e (v, i, SOME n)] folds function f over the subvector
  83.    v[i..i+n-1] from left to right.  That is, computes 
  84.    f(i+n-1, v[i+n-1], f(..., f(i+1, v[i+1], f(i, v[i], e)) ...)).  
  85.    Raises Subscript if i<0 or n<0 or i+n > length v.
  86.  
  87.    [foldli f e (v, i, NONE)] folds function f over the subvector
  88.    v[i..len-1] from left to right, where len =  length v.  That is, 
  89.    computes f(len-1, v[len-1], f(..., f(i+1, v[i+1], f(i, v[i], e)) ...)).  
  90.    Raises Subscript if i<0 or i > length v.
  91.  
  92.    [foldri f e (v, i, SOME n)] folds function f over the subvector
  93.    v[i..i+n-1] from right to left.  That is, computes 
  94.    f(i, v[i], f(i+1, v[i+1], ..., f(i+n-1, v[i+n-1], e) ...)).
  95.    Raises Subscript if i<0 or n<0 or i+n > length v.
  96.  
  97.    [foldri f e (v, i, NONE)] folds function f over the subvector
  98.    v[i..len-1] from right to left, where len = length v.  That is, 
  99.    computes f(i, v[i], f(i+1, v[i+1], ..., f(len-1, v[len-1], e) ...)).
  100.    Raises Subscript if i<0 or i > length v.
  101.  
  102.    [appi f (v, i, SOME n)] applies f to successive pairs (j, v[j]) for
  103.    j=i,i+1,...,i+n-1.  Raises Subscript if i<0 or n<0 or i+n > length v.
  104.  
  105.    [appi f (v, i, NONE)] applies f to successive pairs (j, v[j]) for
  106.    j=i,i+1,...,len-1, where len = length v.  Raises Subscript if i<0
  107.    or i > length v.
  108. *)
  109.