[Haskell-beginners] Re: Iterating through a list of char...
Daniel Fischer
daniel.is.fischer at web.de
Thu Apr 29 17:23:52 EDT 2010
Am Donnerstag 29 April 2010 22:39:05 schrieb Jean-Nicolas Jolivet:
> Every solution I found was iterating to a list of character one
> character at a time, and outputting a character as a result (whether it
> is by recursion, mapping, etc..),
Well, that's necessary for what you want to do, isn't it?
> however, what I was trying to explain
> in my previous post was that; when I am processing the escape character,
> this character should not be added to the resulting string... This is
> where I decided to use the Maybe monad..I'm just wondering if there is a
> better way...!
Depends on your criteria.
For raw performance, I think the directly coded recursion is a bit better
(btw,
fooGen e esc norm = go False
where
go b (x:xs)
| x == e = go True xs
| b = esc x : go False xs
| otherwise = norm x : go False xs
go _ [] = []
).
For code cleanliness, catMaybes&zipWith and a good directly coded recursion
are about equal.
For leetness, the foldr is beats them, but surely one could do much
'better'.
More information about the Beginners
mailing list