[Haskell-cafe] Rewriting filter with foldr

PR Stanley prstanley at ntlworld.com
Sun Sep 30 09:15:40 EDT 2007


Hi
filter :: (a -> Bool) -> [a] -> [a]
filter f = foldr (\x -> \xs -> if (f x) then (x:xs) else xs) []
Somehow I feel this could be done more elegantly. What does the list think?
Thanks, Paul



More information about the Haskell-Cafe mailing list