[Haskell-cafe] ANNOUNCE: The Monad.Reader - Issue 6
David House
dmhouse at gmail.com
Wed Jan 31 17:11:53 EST 2007
On 31/01/07, Pixel <pixel at mandriva.com> wrote:
> i ended up with this one:
>
> dwBool predicate l = (foldr combine (\_ -> []) l) True
> where
> combine e fl beg = if beg && predicate e
> then fl True
> else e : fl False
Mine was:
dw :: (a -> Bool) -> [a] -> [a]
dw p = reverse . fst . foldl comb ([],False)
where comb (xs,done) x | done = (x:xs, True)
| p x = (xs, False)
| otherwise = (x:xs, True)
Which is the simplest working algorithm I could come up with; sadly it
breaks the lazinesss constraint. It was a great article though, seeing
fix's definition in terms of foldr was one of those mind-bending
moments which makes learning Haskell what it is.
--
-David House, dmhouse at gmail.com
More information about the Haskell-Cafe
mailing list