[nem-en] Re: [proposal] foldr1/foldl1
Elifant
elifantu at mail.ru
Wed Jul 11 05:18:56 CEST 2007
Michal Moskal wrote:
>> BTW, I was surprised by the argument order of callback function.
> In Haskell you use: "foldl f ini lst" -- you pass initial accumulator
> before the list, so also the callback takes the accumulator before the
> element of the list. In Nemerle, OTOH you write: "lst.FoldLeft(ini,
> f)", so the list goes before the accumulator in both function
> invocation and the callback.
Sorry, I don't understand this argument.
There is no relation to the absolute list-accumulator order. Even if
Haskell foldl has
signature like in Nemerle:
foldl :: [b] -> (a -> b -> a) -> a -> a
it is still more convenient than
foldl :: [b] -> (a -> a -> b) -> a -> a
because you can write "foldl [2, 3, 4] (>>)" 1 to get "(((1 >> 2) >> 3)
>> 4)
instead of "foldl [2, 3, 4] (flip (>>)) 1"
It is just more intuitive to have accumulator on the left when folding
from left to right, and
accumulator on the right when folding from right to left.
But I understand, that this is too breaking change, I just wanted to
know motivation.
More information about the devel-en
mailing list