home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / Vector.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  5.2 KB  |  123 lines  |  [TEXT/Moml]

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