So something like:
bool done = false;
while (!done) {
...
}
makes no sense unless you have some way of setting `done = true`; which is not possible in purely functional languages like Haskell.So something like:
bool done = false;
while (!done) {
...
}
makes no sense unless you have some way of setting `done = true`; which is not possible in purely functional languages like Haskell.The really funny thing is that the while loop itself is not built-in to Haskell but you can write it yourself as a function. In other languages (non-lazy) this sort of thing is not possible without resorting to macros or other tricks, because laziness is required in order to define the correct semantics for conditionals.
One is through constructs like Clojure's `take-while`. Instead of setting a vairable when you want to exit the loop, you define a predicate that is false when the loop should exit.
Another is through `any` and `all` (aka `some` and `every`), which work in a similar way to `take-while`, except they reduce OR or AND across the returned values from the predicate as they go.
EDIT: grammar and clarity