Dan Piponi wrote:
If you allow me to play Devil's advocate for a moment...just don't let
this guy ask you how long the Haskell version takes.

In fact, you can borrow a trick from the C++ version. Try this instead:

import Data.Set
main = interact $ unlines . toList . fromList . words

Yes - I discovered this one myself last night. ;-)

Seems to run with complexity equal to O(N log M) time and O(M) memory - just as the C++ version does. (But then, Data.Set seems to use the exact implementation that std::set has, so...)

One small puzzling thing... I run it over a file containing 1 million copies of the string "a b ". (That makes a ~90 MB file.) Apparently even a trivial Haskell program uses 21 MB RAM (I'm guessing it's the default heap size or something), but this one did consume slightly more RAM towards the end. (~25 MB.) I'm puzzled as to why this would be...

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to