From prelude:
foldl1: it takes the first 2 items of
the list and applies the function to
them, then feeds the function with
this result and the third argument and
so on.
Why is not possible to write something like this?
foldl1 (==) [6, 6, 6]
foldl1 (\x y -> x == y) [6, 6, 6]
EDIT: Antal points out that my reasoning was incorrect. Here is the relevant part of the comment that gives the real reasoning (I feel bad taking this verbatim, but this answer was accepted so I can’t delete it):
The reason this doesn’t work is that the type of
foldl1is(a -> a -> a) -> [a] -> a, but the type of(==)isNum a => a -> a -> Bool. SinceBoolisn’t aNum,(==)type doesn’t matcha -> a -> a, and so the application offoldl1is rejected. If it were accepted, you’d end up with a situation where you were trying to doTrue == 6, but the type system never gets you get that far in the first place.Original answer (latter reasoning incorrect):
==will take twoInts and return aBool. After the first iteration your example list becomes[True, 6]. It then tries to compareTrueto6which fails.