So let's check out the types of the functions involved
Prelude> :t (\i -> case i of { True -> (1+) ; False -> (0+) })
(\i -> case i of { True -> (1+) ; False -> (0+) }) :: (Num t) => Bool -> t -> t
Prelude> :t foldl
foldl :: (a -> b -> a) -> a -> [b] -> a
So for your list of Bool
s, b is Bool, but the function you're using has Bool
as the first argument, not the second. The accumulated value is the first argument. So instead you could do
foldl (\acc p -> case p of { True -> acc + 1 ; False -> acc }) 0
Or if you'd just like to fix the argument order, use your original function with flip
Prelude> :t flip
flip :: (a -> b -> c) -> b -> a -> c
foldl (flip (\i -> case i of
True -> (1+)
False -> (0+)
)) 0
Or you can be more succinct: foldl (flip ((+) . fromEnum)) 0