| 1 |
(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh |
| 2 |
* Jagannathan, and Stephen Weeks. |
| 3 |
* Copyright (C) 1997-2000 NEC Research Institute. |
| 4 |
* |
| 5 |
* MLton is released under a HPND-style license. |
| 6 |
* See the file MLton-LICENSE for details. |
| 7 |
*) |
| 8 |
|
| 9 |
structure Natural = |
| 10 |
struct |
| 11 |
fun foldStartStop (start, stop, b, f) = |
| 12 |
if start > stop |
| 13 |
then raise Subscript |
| 14 |
else |
| 15 |
let |
| 16 |
fun loop (i, b) = |
| 17 |
if i >= stop then b |
| 18 |
else loop (i + 1, f (i, b)) |
| 19 |
in loop (start, b) |
| 20 |
end |
| 21 |
|
| 22 |
fun foreachStartStop (start, stop, f) = |
| 23 |
foldStartStop (start, stop, (), fn (i, ()) => f i) |
| 24 |
|
| 25 |
fun foreach (n, f) = foreachStartStop (0, n, f) |
| 26 |
end |