Home My Page Projects Code Snippets Project Openings SML/NJ
 Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

# SCM Repository

[smlnj] View of /smlnj-lib/trunk/Util/iterate-sig.sml
 [smlnj] / smlnj-lib / trunk / Util / iterate-sig.sml

# View of /smlnj-lib/trunk/Util/iterate-sig.sml

Thu Nov 2 16:23:11 2006 UTC (12 years, 11 months ago) by blume
File size: 925 byte(s)
`moved smlnj-lib to toplevel`
```(* iterate-sig.sml
*
* COPYRIGHT (c) 1993 by AT&T Bell Laboratories.  See COPYRIGHT file for details.
*
*)

signature ITERATE =
sig

val iterate : ('a -> 'a) -> int -> 'a -> 'a
(* iterate f cnt init = f(f(...f(f(init))...)) (cnt times)
* iterate f 0 init = init
* raises BadArg if cnt < 0
*)

val repeat : (int * 'a -> 'a) -> int -> 'a -> 'a
(* repeat f cnt init
*     = #2(iterate (fn (i,v) => (i+1,f(i,v))) cnt (0,init))
*)

val for : (int * 'a -> 'a) -> (int * int * int) -> 'a -> 'a
(* for f (start,stop,inc) init
*      "for loop"
*      implements f(...f(start+2*inc,f(start+inc,f(start,init)))...)
*      until the first argument of f > stop if inc > 0
*         or the first argument of f < stop if inc < 0
* raises BadArg if inc <= 0 and start < stop or if inc >=0 and
* start > stop.
*)

end (* ITERATE *)
```