Another Newbie question :)
Hal Daume III
hdaume at ISI.EDU
Wed Nov 5 07:17:23 EST 2003
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
More information about the Haskell-Cafe
mailing list