andrewcoppin at btinternet.com
Thu Dec 10 15:49:05 EST 2009
John D. Earle wrote:
> What material benefit does Haskell derive from being a "pure"
> functional language as opposed to an impure one?
1. Code optimisation becomes radically easier. The compiler can make
very drastic alterations to your program, and not chance its meaning.
(For that matter, the programmer can more easily chop the code around
2. Purity leads more or less directly to laziness, which has several
2a. Unecessary work can potentially be avoided. (E.g., instead of a
function for getting the first solution to an equation and a seperate
function to generate *all* the solutions, you can just write the latter
and laziness gives you the former by magic.)
2b. You can define brand new flow control constructs *inside* the
language itself. (E.g., in Java, a "for" loop is a built-in language
construct. In Haskell, "for" is a function in Control.Monad. Just a
plain ordinary function that anybody could write.)
2c. The algorithms for generating data, selecting data and processing
data can be seperated. (Normally you'd have to hard-wire the stopping
condition into the function that generates the data, but with lazy
"infinite" data structures, you can seperate it out.)
2d. Parallel computation. This turns out to be more tricky than you'd
think, but it's leaps and bounds easier than in most imperative languages.
3. It's much harder to accidentally screw things up by modifying a piece
of data from one part of the program which another part is still
actually using. (This is somewhat similar to how garbage collection
makes it harder to free data that's still in use.)
That's at least 6 really huge reasons why purity is a massive win.
More information about the Haskell-Cafe