On 12/12/2012 3:23 PM, Timon Gehr wrote:
On 12/12/2012 10:35 PM, Walter Bright wrote:
some algorithms are doomed to be slower.
Here's a (real) quicksort:
http://stackoverflow.com/questions/5268156/how-do-you-do-an-in-place-quicksort-in-haskell
Ok, I'll bite.
Here's a program in Haskell and D that reads from standard in, splits into
lines, sorts the lines, and writes the result the standard out:
==============================
import Data.List
import qualified Data.ByteString.Lazy.Char8 as L
main = L.interact $ L.unlines . sort . L.lines
==============================
import std.stdio;
import std.array;
import std.algorithm;
void main() {
stdin.byLine(KeepTerminator.yes)
map!(a => a.idup).
array.
sort.
copy(
stdout.lockingTextWriter());
}
===============================
The D version runs twice as fast as the Haskell one. Note that there's nothing
heroic going on with the D version - it's straightforward dumb code.