Phix vs Functional Languages
I recently read
an academic paper
that contained the following anecdote, which I thought was worth sharing.
The Sieve of Eratosthenes has been cited in introductions to lazy functional programming for more than 30 years. In Haskell, the code is as follows
Apparently one implementation (not Haskell, but that did not fare well either) was so grotesquely inefficient that it would take "several seconds" to calculate the 19th prime (ie 71) ...
Words just utterly fail me.
The Sieve of Eratosthenes has been cited in introductions to lazy functional programming for more than 30 years. In Haskell, the code is as follows
primes = sieve [2..]
sieve (p : xs) = p : sieve [x | x <- xs, x `mod` p > 0]
which is not that algorithm
at all but in fact something significantly worse than trial division. The use of mod is a pretty big clue, and trial
division is normally considered the most naive and inefficient way, so finding something even less efficient, and
then teaching it all over the world for over thirty years, ... well.
Apparently one implementation (not Haskell, but that did not fare well either) was so grotesquely inefficient that it would take "several seconds" to calculate the 19th prime (ie 71) ...
Words just utterly fail me.