Open const-rs opened 8 years ago
It is not a very functional programming style to use loops. Why not just define a combinator?
fun foreach (lo, hi) f = let
fun lp i = if (i <= hi) then (f i; lp(i+1)) else ()
in
lp lo
end
so you can write
foreach (1, 18) (fn i => ...)
If we are going to add syntax for loops, then I would be much more interested in list/vector comprehensions.
What about including Ocaml-style for cycle:
for i = 1 to 18 do ... done (or end)
It is very handy when iterating through arrays or strings. Also, it does not let one make common mistake with repeating calls in condition, like
for( i = 0; i < strlen(s); i++)