here is my code:
boolTrueList :: [Bool] -> Bool
boolTrueList xs
| length (filterFalse xs) > 0 = False
| otherwise = True
where
filterFalse = filter (==False)
This is perfectly working, however I would like to rewrite the same thing with foldr/foldl, but I am stuck.
My idea is to fold a list until I find a false value and then, stop.
Any hint?
If you want to stop early, you have to use
foldr.foldlalways has to traverse the entire list (so doesn’t work at all on infinite lists).So you want
The
defaultis the result for an empty list, that would beTruehere. Now, how would we want to combine?When a
Falseis encountered, we want to return False immediately, soand when the value is
True, we must go on, soIn other words,
combine = (&&), soor, even shorter