Iterate
structure
signature ITERATE
structure Iterate
: ITERATE
The Iterate structure provides wrappers for simple forms of iteration.
val iterate : ('a -> 'a) -> int -> 'a -> 'a
val repeat : ((int * 'a) -> 'a) -> int -> 'a -> 'a
val for : ((int * 'a) -> 'a) -> (int * int * int) -> 'a -> 'a
iterate f cnt a
iterate f cnt v = iterate f (cnt-1) (f v) iterate f 0 v = vRaises the Fail exception if cnt is negative.
repeat f cnt a
iterate
except that the function f is also passed the iteration index. In particular, it is equivalent to:
#2(iterate (fn (i,v) => (i+1,f(i,v))) cnt (0,init))
for f (start, stop, inc) a
for f (start,stop,inc) a = for f (start+inc,stop,inc) (f(start,a))halting when start > stop for negative inc and halting when stop > start for positive inc. If inc is zero, start and ~TOP must be equal, and we have
for f (start,stop,0) a = f(start,a)Raises Fail if either inc is non-positive and stop > start, or if inc is non-negative and start > stop.
Last Modified June 10, 1998
Comments to John Reppy
Copyright © 1998 Bell Labs, Lucent Technologies