I am new to Haskell and will play a little. I created a recursive function with protection. See Function below:
filterAge :: [Person] -> [String]
filterAge (x:xs)
| (x:xs) == [] = []
| (getAge x) < 30 || (getAge x) > 40 = [] ++ filterAge xs
| otherwise = [getName x] ++ filterAge xs
I have a dataset created using 10 people that I use in this method. When I tried this function, it gave all the right people, but after that I got an error not related to the exhaustive templates:
["Lise","Jaap","Elle","Ebba"*** Exception: D:\...:(44,1)-(47,77): Non-exhaustive patterns in function filterAge
I learned that he never reaches the first guard. So I played a little and found out something really strange (in my opinion):
*Main> let (x:xs) = []
*Main> (x:xs) == []
False
Now my main question is: why (x:xs) == []returns False?
If someone has a better way for me to make a function that will be great, but that is not very important.
Thanks in advance!
EDIT
Willem Van Onsem Lambda.xy.x . , :
filterAge :: [Person] -> [String]
filterAge [] = []
filterAge (x:xs)
| (getAge x) < 30 || (getAge x) > 40 = [] ++ filterAge xs
| otherwise = [getName x] ++ filterAge xs
.