> 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.
Speaking of the laziness constraint, the simplest solution to the strictness of dwBackwards (solution 1) would be to use irrefutable pattern matching in the combine function: dwBackwards predicate = fst . foldr combine ([],[]) where -- Note the tilde in the next line... combine x ~(ys,xs) | predicate x = (ys, x:xs) | otherwise = (x:xs, x:xs) _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe