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

  1. (* ListPair -- SML Basis Library *)
  2.  
  3. val zip    : 'a list * 'b list -> ('a * 'b) list
  4. val unzip  : ('a * 'b) list -> 'a list * 'b list
  5. val map    : ('a * 'b -> 'c)   -> 'a list * 'b list -> 'c list
  6. val app    : ('a * 'b -> unit) -> 'a list * 'b list -> unit
  7. val all    : ('a * 'b -> bool) -> 'a list * 'b list -> bool
  8. val exists : ('a * 'b -> bool) -> 'a list * 'b list -> bool
  9. val foldr  : ('a * 'b * 'c -> 'c) -> 'c -> 'a list * 'b list -> 'c
  10. val foldl  : ('a * 'b * 'c -> 'c) -> 'c -> 'a list * 'b list -> 'c
  11.  
  12.  
  13. (* These functions process pairs of lists.  No exception is raised
  14.    when the lists are found to be of unequal length.  Instead the
  15.    excess elements from the longer list are disregarded.
  16.  
  17.    [zip (xs, ys)] returns the list of pairs of corresponding elements
  18.    from xs and ys.  
  19.  
  20.    [unzip xys] returns a pair (xs, ys), where xs is the list of first
  21.    components of xys, and ys is the list of second components from
  22.    xys.  Hence zip (unzip xys) has the same result and effect as xys.
  23.  
  24.    [map f (xs, ys)] applies function f to the pairs of corresponding
  25.    elements of xs and ys and returns the list of results.  Hence 
  26.    map f (xs, ys) has the same result and effect as List.map f (zip (xs, ys)).
  27.  
  28.    [app f (xs, ys)] applies function f to the pairs of corresponding
  29.    elements of xs and ys and returns ().  Hence app f (xs, ys) has the
  30.    same result and effect as List.app f (zip (xs, ys)).
  31.  
  32.    [all p (xs, ys)] applies predicate p to the pairs of corresponding
  33.    elements of xs and ys until p evaluates to false or one or both
  34.    lists is exhausted; returns true if p is true of all such pairs;
  35.    otherwise false.  Hence all p (xs, ys) has the same result and
  36.    effect as Lisp.all p (zip (xs, ys)).
  37.  
  38.    [exists p (xs, ys)] applies predicate p to the pairs of corresponding
  39.    elements of xs and ys until p evaluates to true or one or both
  40.    lists is exhausted; returns true if p is true of any such pair;
  41.    otherwise false.  Hence exists p (xs, ys) has the same result and
  42.    effect as Lisp.exists p (zip (xs, ys)).
  43.  
  44.    [foldr f e (xs, ys)] evaluates f(x1, y1, f(x2, y2, f(..., f(xn, yn, e))))
  45.    where xs = [x1, x2, ..., x(n-1), xn, ...],
  46.          ys = [y1, y2, ..., y(n-1), yn, ...], 
  47.    and    n = min(length xs, length ys).
  48.    Equivalent to List.foldr (fn ((x, y), r) => f(x, y, r)) e (zip(xs, ys)).
  49.  
  50.    [foldl f e (xs, ys)] evaluates f(xn, yn, f( ..., f(x2, y2, f(x1, y1, e))))
  51.    where xs = [x1, x2, ..., x(n-1), xn, ...], 
  52.          ys = [y1, y2, ..., y(n-1), yn, ...], 
  53.    and    n = min(length xs, length ys).
  54.    Equivalent to List.foldl (fn ((x, y), r) => f(x, y, r)) e (zip(xs, ys)).
  55. *)
  56.