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

  1. (* List -- SML Basis Library *)
  2.  
  3. type 'a list = 'a list
  4.  
  5. exception Empty  (* Subscript and Size *)
  6.  
  7. val null       : 'a list -> bool
  8. val hd         : 'a list -> 'a                          (* Empty     *)
  9. val tl         : 'a list -> 'a list                     (* Empty     *)
  10. val last       : 'a list -> 'a                          (* Empty     *)
  11.  
  12. val nth        : 'a list * int -> 'a                    (* Subscript *)
  13. val take       : 'a list * int -> 'a list               (* Subscript *)
  14. val drop       : 'a list * int -> 'a list               (* Subscript *)
  15.  
  16. val length     : 'a list -> int 
  17.  
  18. val rev        : 'a list -> 'a list 
  19.  
  20. val @          : 'a list * 'a list -> 'a list
  21. val concat     : 'a list list -> 'a list
  22. val revAppend  : 'a list * 'a list -> 'a list
  23.  
  24. val app        : ('a -> unit) -> 'a list -> unit
  25. val map        : ('a -> 'b) -> 'a list -> 'b list
  26. val mapPartial : ('a -> 'b option) -> 'a list -> 'b list
  27.  
  28. val find       : ('a -> bool) -> 'a list -> 'a option
  29. val filter     : ('a -> bool) -> 'a list -> 'a list
  30. val partition  : ('a -> bool ) -> 'a list -> ('a list * 'a list)
  31.  
  32. val foldr      : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
  33. val foldl      : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
  34.  
  35. val exists     : ('a -> bool) -> 'a list -> bool
  36. val all        : ('a -> bool) -> 'a list -> bool
  37.  
  38. val tabulate   : int * (int -> 'a) -> 'a list           (* Size      *)
  39.  
  40. val getItem    : 'a list -> ('a * 'a list) option
  41.  
  42. (* 
  43.    [null xs] is true iff xs is nil.
  44.  
  45.    [hd xs] returns the first element of xs.  Raises Empty if xs is nil.
  46.  
  47.    [tl xs] returns all but the first element of xs.  
  48.    Raises Empty if xs is nil.
  49.  
  50.    [last xs] returns the last element of xs.  Raises Empty if xs is nil.
  51.  
  52.    [nth(xs, i)] returns the i'th element of xs, counting from 0.
  53.    Raises Subscript if i<0 or i>=length xs.
  54.  
  55.    [take(xs, i)] returns the first i elements of xs.  Raises Subscript
  56.    if i<0 or i>length xs.
  57.  
  58.    [drop(xs, i)] returns what is left after dropping the first i
  59.    elements of xs.  Raises Subscript if i<0 or i>length xs.  
  60.    It holds that take(xs, i) @ drop(xs, i) = xs when 0 <= i <= length xs.
  61.  
  62.    [length xs] returns the number of elements in xs.
  63.  
  64.    [rev xs] returns the list of xs's elements, reversed.
  65.  
  66.    [xs @ ys] returns the list which is the concatenation of xs and ys.
  67.  
  68.    [concat xss] returns the list which is the concatenation of all the
  69.    lists in xss.
  70.  
  71.    [app f xs] applies f to the elements of xs, from left to right.
  72.  
  73.    [map f xs] applies f to each element x of xs, from left to
  74.    right, and returns the list of f's results.
  75.  
  76.    [mapPartial f xs] applies f to each element x of xs, from left
  77.    to right, and returns the list of those y's for which f(x)
  78.    evaluated to SOME y.
  79.  
  80.    [find p xs] applies f to each element x of xs, from left to
  81.    right until p(x) evaluates to true; returns SOME x if such an x
  82.    exists otherwise NONE.
  83.  
  84.    [filter p xs] applies p to each element x of xs, from left to
  85.    right, and returns the sublist of those x for which p(x) evaluated
  86.    to true.
  87.  
  88.    [partition p xs] applies p to each element x of xs, from left
  89.    to right, and returns a pair (pos, neg) where pos is the sublist
  90.    of those x for which p(x) evaluated to true, and neg is the sublist of
  91.    those for which p(x) evaluated to false.
  92.  
  93.    [foldr op% e xs] evaluates x1 % (x2 % ( ... % (x(n-1) % (xn % e)) ... ))
  94.    where xs = [x1, x2, ..., x(n-1), xn], and % is taken to be infixed.
  95.  
  96.    [foldl op% e xs] evaluates xn % (x(n-1) % ( ... % (x2 % (x1 % e))))
  97.    where xs = [x1, x2, ..., x(n-1), xn], and % is taken to be infixed.
  98.  
  99.    [exists p xs] applies p to each element x of xs, from left to
  100.    right until p(x) evaluates to true; returns true if such an x
  101.    exists, otherwise false.
  102.  
  103.    [all p xs] applies p to each element x of xs, from left to
  104.    right until p(x) evaluates to false; returns false if such an x
  105.    exists, otherwise true.
  106.  
  107.    [tabulate(n, f)] returns a list of length n whose elements are
  108.    f(0), f(1), ..., f(n-1), created from left to right.  Raises Size
  109.    if n<0.
  110.  
  111.    [getItem xs] attempts to extract an element from the list xs.  It
  112.    returns NONE if xs is empty, and returns SOME (x, xr) if xs=x::xr.
  113.    This can be used for scanning booleans, integers, reals, and so on
  114.    from a list of characters.  For instance, to scan a decimal integer
  115.    from a list cs of characters, compute 
  116.     Int.scan StringCvt.DEC List.getItem cs
  117. *)
  118.