[Haskell-cafe] Re: If the local variable can be changed ...
monnier at iro.umontreal.ca
Wed Mar 10 11:00:50 EST 2010
> So if the local variable can be changed, then we can use loop,
> etc. same as imperative languages. For example, for (i=0; i<100; i++)
> where `i` is a local variable in function.
It is true that a pure language could support such things (some pure
languages do, e.g. Sisal). The experience of people using SML and
Haskell seems to indicate that this is not very important in those
languages: it's easy for the programmer to turn his variable-assignments
into something pure (using new variables instead), and it's reasonably
easy as well for the compiler to recognize loops and handle them just as
efficiently as if they were while/for loops in an imperative language.
OTOH, allowing modification of variables makes the whole language
impure, because of variables caught in closures, e.g.:
let count = 0
in \() -> count := count + 1; count
so it has very far reaching consequences.
More information about the Haskell-Cafe