I would like to have a function that checks if a list contains only even numbers; if so, it should return True, otherwise – False.
Functions I would like to use are map / filter / foldr, possibly without length.
Here is my attempt:
ListOfeven :: [Integral] -> Bool
ListOfeven xs =
| foldr (+) True filter odd xs < 0 = True
| otherwise = False
I am pretty sure that there is a cleaner way.. isn’t there any? 🙂
The easiest would be to just use the
allfunction from the Prelude:If you insist on just using
map,filterandfoldr: