[nem-en] Re: [proposal] foldr1/foldl1
Kamil Skalski
kamil.skalski at gmail.com
Tue Jul 10 10:41:41 CEST 2007
+ while (not_end)
+ accum = convert(value, accum);
+ not_end = enumerator.MoveNext ();
Looks like you are missing the { }
It would be nice to have also a patch for tests in
nemerle/lib/tests/
or
nemerle/ncc/testsuite/positive/collections.n
Otherwise it looks ok, but I think the best approach is to have the
tests and then we can easily apply it to trunk and check if it
compiles fine and the tests are passing.
>
> IEnumerable.FoldRight is implemented using temporary array (just because
> existing FoldRight
> does that) instead of recursion. Is it preferred way?
Yes, since we can avoid stack overflow and AFAIR allocation of a temp
array is not very costly. What I'm not sure about is how the
source.ToArray ();
performs. I guess it does another temporary allocations and given that
it should be possible to use the same method directly and not allocate
the array.
>
>
> BTW, I was surprised by the argument order of callback function. I was
> expecting that
I'm afraid it is too large breaking change, since for cases when acc
type is the same as value type user will not every know that something
changed and his program will start behaving unexpectedly.
Maybe create another function for that, howevery I don't like this too
much, we should stick to single parameters order in all fuctions and
AFAIR there are many functions with similar signature.
>
> [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.
>
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>
>
>
--
Kamil Skalski
http://nazgul.omega.pl
More information about the devel-en
mailing list