> ...
> Q. Do other languages do it?
> A. Numpy, no. R, no. APL, no. Mathematica, no. Haskell, yes.
>    ...
>     *

Haskell has millions of functions ;-)  `mapAccumL` is a God-awful
mixture of Python's map(), reduce(), and accumulate() :-(  The
examples here should convince you it's nearly incomprehensible:

A more-than-less direct equivalent to Python's `accumulate` is
Haskell's `scanl1`:

That doesn't allow specifying an initial value.  But, Haskell being
Haskell, the closely related `scanl` function requires specifying an
initial value, which is also the first element of the list it returns:

Of the two, `scanl` is more basic - indeed, the Standard Prelude
defines scanl1 by peeling off the first element of the list and
passing it as the initial value for scanl to use

scanl            :: (a -> b -> a) -> a -> [b] -> [a]
scanl f q xs     =  q : (case xs of
                            []   -> []
                            x:xs -> scanl f (f q x) xs)

scanl1           :: (a -> a -> a) -> [a] -> [a]
scanl1 f (x:xs)  =  scanl f x xs
scanl1 _ []      =  []

There are also analogous `scanr` and `scanr1` functions for doing
"right-to-left" accumulation.

So, bottom line:  as usual, when looking to Haskell for prior art,,
"all of the above - for a start" applies ;-)
Python-ideas mailing list
Code of Conduct:

Reply via email to