[Haskell-cafe] Reversing a string of words: C# v Perl V Ruby v
Haskell
Greg Fitzgerald
garious at gmail.com
Mon Dec 11 20:07:28 EST 2006
Hi Steve,
On 12/11/06, Steve Downey <sdowney at gmail.com> wrote:
> transforming "one two three four " into " four three two
one", how could this be done?
This is a good problem for
Parsec<http://www.cs.uu.nl/%7Edaan/download/parsec/parsec.html>
:
import Text.ParserCombinators.Parsec
reverseWords = concat . reverse . split
where
split = fromRight . parse wordsSpaces ""
fromRight (Right s) = s
wordsSpaces = many (many1 space <|> many1 alphaNum)
-Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061211/e061df9b/attachment-0001.htm
More information about the Haskell-Cafe
mailing list