Understanding Haskell's filter
Posted
by dmindreader
on Stack Overflow
See other posts from Stack Overflow
or by dmindreader
Published on 2010-04-02T17:59:56Z
Indexed on
2010/04/02
18:03 UTC
Read the original article
Hit count: 296
haskell
I understand that Haskell's filter is a high order function (meaning a function that takes another function as a parameter) that goes through a list checking which element fulfills certain boolean condition.
I don't quite understand its definition:
filter:: (a->Bool)->[a]->[a]
filter p [] = []
filter p (x:y) | p x = x:filter p y | otherwise =
filter p y
I understand that if I pass an empty list to the function, it would just return an empty list, but how do I read the last two lines?
© Stack Overflow or respective owner