[Haskell-cafe] Reversing a string of words: C# v Perl V Ruby v Haskell

Donald Bruce Stewart dons at cse.unsw.edu.au
Wed Dec 13 20:19:20 EST 2006

> ok, i'll bite. why should i prefer join rather than concat in the list
> monad. and, moreover, why is this a lambdabot trick?

Oh, but you shouldn't prefer it! It's obfuscating!

It's a trick simply because lambdabot knows the rewriting:

    12:16  dons> ?pl reverseWords = concat . reverse . groupBy ((==) `on` isSpace)
    12:16  lambdabot> reverseWords = join . reverse . groupBy ((==) `on` isSpace)

Refactoring autobots to the resuce!
> i suspect that the answer actually has a deep connection to the
> 'dummies' thread next door.  while any program that produces the right
> result is correct, there are some that are more correct than others. a
> good introductory guide to haskell should lead you in that direction.
> reasoning by analogy, for c++, andy koenig's accelerated c++ had a
> huge impact on teaching c++ because it didn't start with C or pidgen
> c++, but instead required the student to accept that many mechanisms
> would be explained later, but that they should be used -now-.
> i suspect that being biased towards higher order functions, and
> writing new functions such that monads (although the more i learn i
> think that should be typeclasses) can take advantage of those
> functions, is the skill that needs to be learned / taught. the
> equivalent of the central dogma of OO, where it's all about objects
> having identity, state , and behavior.

Yes, and I think a proper understanding of higher order functions,
parametric and bounded polymorphism and monadic computations is sorely
lacking in a lot of undergraduate courses.

With monads in C#, and parametric polymorphism in Java, I wonder how
long it will be before you're expected to understand these concepts to
program real world Java/C#/...

-- Don

More information about the Haskell-Cafe mailing list