
5 Nov
2003
5 Nov
'03
10:17 a.m.
Keith is entirely correct.
You can see this from the definition of foldr:
foldr :: (a -> b -> b) -> b -> [a] -> b foldr f z [] = z foldr f z (x:xs) = f x (foldr f z xs)
where clearly every [] is replaced by z and every : by f.
I had heard this before when I was first beginning and didn't really find it "clear" :). I think if you write foldr with f in infix notation it's a bit more clear:
foldr f z [] = z foldr f z (x:xs) = x `f` foldr f z xs
or even write the second line as
foldr f z (x:xs) = x `f` xs' where xs' = foldr f z xs
I think in this case it's a bit more clear how "f" is replacing the ":". - Hal