Improve my Haskell implementation of Filter
Posted
by mvid
on Stack Overflow
See other posts from Stack Overflow
or by mvid
Published on 2010-06-10T02:42:46Z
Indexed on
2010/06/10
2:52 UTC
Read the original article
Hit count: 296
I have recently been teaching myself Haskell, and one of my exercises was to re-implement the filter
function. However, of all the exercises I have performed, my answer for this one seems to me the most ugly and long. How could I improve it? Are there any Haskell tricks I don't yet know?
myfilter :: (a -> Bool) -> [a] -> [a]
myfilter f (x:xs) = if f x
then x : myfilter f xs
else myfilter f xs
myfilter _ [] = []
Thank You
© Stack Overflow or respective owner