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

Bernie Pope bjpop at csse.unimelb.edu.au
Sun Dec 10 08:48:46 EST 2006


On 10/12/2006, at 11:51 PM, Neil Mitchell wrote:

> Hi
>
>> What about just:
>>
>>     reverseWords = concat . intersperse " " . reverse . words
>
> Dr Haskell says:
> [http://www-users.cs.york.ac.uk/~ndm/projects/drhaskell.php]
>
> "Use unwords instead of concat (intersperse space ...)"
>
> Which gives us:
>
> reverseWords = unwords . reverse . words

Lovely stuff.

Just in case you prefer reading left-to-right, another variation is:

    import Control.Arrow

    reverseWords = words >>> reverse >>> unwords


More information about the Haskell-Cafe mailing list