On 24 Jan 2008, at 3:04 PM, Evan Laforge wrote:

This takes an iterator over some collection of Foos and finds the one
with the highest value of updateTime. 9 lines of code, or 12 with the
closing curly brackets.

In Haskell this is so short and obvious you probably wouldn't bother
declaring it as a function, but if you did, here it is:

   -- Find the Foo that was most recently updated.
   latestUpdate :: [Foo] -> Foo
   latestUpdate foos = maximumBy (comparing updateTime) foos

Of course you could always write it in point-free format, but I think
that would be over-egging things.

Java's just wordy like that.  In python you'd say max(foos, key=lambda
x: x.update_time).  Python / perl / ruby / smalltalk have had first
class functions forever, so those are basically already in the
mainstream.

But, while Python/Perl/Ruby/Smalltalk may have borrowed such techniques already, the syntax still conspires against them. If the audience knows one or more of these languages, I would suggest finding its syntactic infelicities and contrasting with Haskell (Haskell's syntax is its strongest point, IMHO).

jcc


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to