[nem-en] Re: [proposal] foldr1/foldl1

Elifant elifantu at mail.ru
Tue Jul 10 04:42:35 CEST 2007


Kamil Skalski пишет:

>> > Will you commit the changes or prepare a patch?
>> I can commit. Is SVN public-writeable?

Unfortunately, I am sticked to Mono 1.2.2.1, so I can't compile Nemerle 
and check changes.
Thus I've attached patch, please verify and apply.

IEnumerable.FoldRight is implemented using temporary array (just because 
existing FoldRight
does that) instead of recursion. Is it preferred way?


BTW, I was surprised by the argument order of callback function. I was 
expecting that

[a, b, c, d].FoldLeft(@>>) produces (((a >> b) >> c) >> d), and
[a, b, c, d].FoldRight(@>>) produces (a >> (b >> (c >> d)))

but in fact I need to use [a, b, c, d].FoldLeft((elem, acc) => acc >> elem)

Haskell, for example, has following (convenient) signatures:
Prelude.foldl	:: (a -> b -> a) -> a -> [b] -> a  -- accumulator is on 
the left
Prelude.foldr	:: (a -> b -> b) -> b -> [a] -> b  -- accumulator is on 
the right

This change will break backward compatibility, but you did it several 
times already,
so I hope you will want to make this change now, until it is too late.
To be clear, this change isn't included to the patch, this is just a 
proposal.

Thanks for attention.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: foldleft.patch
Type: text/x-patch
Size: 8481 bytes
Desc: not available
Url : /mailman/pipermail/devel-en/attachments/20070710/a07989f9/foldleft.bin


More information about the devel-en mailing list