On Thu, 20 Sep 2012 13:55:48 +0200, bearophile <[email protected]> wrote:

Section 2.3 is about Scan operations, that are like reduce or fold, but keep all the intermediate results too:

+\ of 3 1 2 4

is 3 4 6 10

Some lazy scans are present in the Haskell Prelude too (and in Mathematica) (the Prelude contains functions and constants that are loaded on default):
http://zvon.org/other/haskell/Outputprelude/scanl_f.html

I think scans are not present in Phobos. Maybe one or two are worth adding.

See attached. Mayhaps I should post this as a pull request?


------------------

Section 2.5 suggests to generalize the dot product:

If the + and * of the Fortran 77 DO loops for inner product are replaced by other functions, a whole family of interesting inner products appear,<

Some examples of usage (in J language):

Associative search                   *./..=y
Inverted associative                 x+./..~:y
Minima of residues for primes        x<./..|y
Transitive closure step on Booleans  y+./..*.y
Minima of maxima                     x<./..>.y

Maybe a higher order function named "dot" (that takes two callables) is worth adding to Phobos. But I am not sure.

So that's basically mapReduce, right? We've got that, just not as succinct.


--
Simen

Attachment: scan.d
Description: Binary data

  • From APL bearophile
    • Re: From APL Simen Kjaeraas

Reply via email to