[Haskell-cafe] Made me smile

Andrew Coppin andrewcoppin at btinternet.com
Sat May 19 04:17:55 EDT 2007


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...



More information about the Haskell-Cafe mailing list