What I suspect happened:
- At some point the Python track might have been in sync with the canonical data.
- The Python track then subconsciously adopted the Haskell tradition through an additional test.
- Later on, in an effort to cover associativity, the canonical data adopted a different tradition.
- Attempting to synchronize, the Python track ran into a conflict and as a quick solution removed the now-offending canonical test.
So I don’t think the Python track truly deviated.
Neither aspects are really the issue here. Instead, it is the parameter order of the accumulating function:
haskell_tradition = lambda acc, new: (acc, new)
racket_tradition = lambda new, acc: (acc, new)
reduce(haskell_tradition, [1, 2, 3], ())
# ⟹ ((((), 1), 2), 3)
reduce(racket_tradition, [1, 2, 3], ())
# ⟹ (3, (2, (1, ())))
list(accumulate([1, 2, 3], haskell_tradition, initial=()))
# ⟹ [(), ((), 1), (((), 1), 2), ((((), 1), 2), 3)]
list(accumulate([1, 2, 3], racket_tradition, initial=()))
# ⟹ [(), (1, ()), (2, (1, ())), (3, (2, (1, ())))]
But yes, Python follows the Haskell tradition here. Python’s reduce
is like Haskell’s foldl
, and accumulate
is like scanl
.
(Why I use the terms «Haskell tradition» and «Racket tradition»: StackOverflow answer.)
By the way: Haskell’s foldr
also works left-to-right, and any foldr
in Python that works on infinite iterators will work left-to-right as well – though such a foldr
might be annoying to construct in Python (because laziness is required).
Given an Iterator Ops I am not in a hurry to deprecate List Ops.
I would like both exercise appends/introductions to point to each other. List Ops could use some fleshing out of the appendage anyway.
I do not see the use of freezing List Ops.
Coming back to the original issue…
The current tests do not cover accumulating functions that are not associative. This does look like a bug to me: associativity is the defining difference between foldl
and foldr
.
The point of both d7fcad99-e88e-40e1-a539-4c519681f390
(foldl
) and 8066003b-f2ff-437e-9103-66e6df474844
(foldr
) and their predecessors was to cover these cases. Maybe we should just revert to said predecessors.