
OK, so I was hanging out on this newsgroup I often lurk. And we're having a discussion. And I'm all like "Haskell is the greatest!" And they're all like "nah, Haskell sux". And this one dude goes "hey, look at this C++ code. How do you do that in Haskell?" And three other people look at this C++ and can't figure out what the heck it even does. So eventually he tells us what it does, and so I post some Haskell in a reply. And the some other guy writes this... (OK, not much point to this email. But it seriously made me LOL IRL!) Invisible wrote:
int main() { typedef std::istream_iteratorstd::string Is; typedef std::ostream_iteratorstd::string Os; std::setstd::string t((Is(std::cin)), Is()); std::copy(t.begin(), t.end(), Os(std::cout, "\n")); }
OK then. main = interact $ unlines . sort . nub . words
Pwned! -- Darren New / San Diego, CA, USA (PST) His kernel fu is strong. He studied at the Shao Linux Temple.

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
Assuming Data.Set is implemented the way I think it is it should
perform much better than the sort . nub version.
--
Dan
On 5/18/07, Andrew Coppin
OK, so I was hanging out on this newsgroup I often lurk. And we're having a discussion. And I'm all like "Haskell is the greatest!" And they're all like "nah, Haskell sux". And this one dude goes "hey, look at this C++ code. How do you do that in Haskell?" And three other people look at this C++ and can't figure out what the heck it even does. So eventually he tells us what it does, and so I post some Haskell in a reply. And the some other guy writes this...
(OK, not much point to this email. But it seriously made me LOL IRL!)
Invisible wrote:
int main() { typedef std::istream_iteratorstd::string Is; typedef std::ostream_iteratorstd::string Os; std::setstd::string t((Is(std::cin)), Is()); std::copy(t.begin(), t.end(), Os(std::cout, "\n")); }
OK then. main = interact $ unlines . sort . nub . words
Pwned!
-- Darren New / San Diego, CA, USA (PST) His kernel fu is strong. He studied at the Shao Linux Temple. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

How does the type of fromList get determined? And is Data.Set.toList the same as Data.Set.toAscList? 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
Assuming Data.Set is implemented the way I think it is it should perform much better than the sort . nub version. -- Dan
On 5/18/07, Andrew Coppin
wrote: OK, so I was hanging out on this newsgroup I often lurk. And we're having a discussion. And I'm all like "Haskell is the greatest!" And they're all like "nah, Haskell sux". And this one dude goes "hey, look at this C++ code. How do you do that in Haskell?" And three other people look at this C++ and can't figure out what the heck it even does. So eventually he tells us what it does, and so I post some Haskell in a reply. And the some other guy writes this...
(OK, not much point to this email. But it seriously made me LOL IRL!)
Invisible wrote:
int main() { typedef std::istream_iteratorstd::string Is; typedef std::ostream_iteratorstd::string Os; std::setstd::string t((Is(std::cin)), Is()); std::copy(t.begin(), t.end(), Os(std::cout, "\n")); }
OK then. main = interact $ unlines . sort . nub . words
Pwned!
-- Darren New / San Diego, CA, USA (PST) His kernel fu is strong. He studied at the Shao Linux Temple. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 5/18/07, Dan Weston
How does the type of fromList get determined? And is Data.Set.toList the same as Data.Set.toAscList?
As I import just Data.Set there is only one fromList in scope. It has type (Ord a) => [a] -> Set a so there is no ambiguity. I should have used toAscList to get a sorted list. toList gives no guarantee of the order of the resulting list but in actual fact, if you peek at the source code, they are the same function so I got away with it.

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...
participants (3)
-
Andrew Coppin
-
Dan Piponi
-
Dan Weston