On 9/20/22 2:02 AM, Marc Nieper-Wißkirchen wrote:
> Is there a reason why you cite Haskell's fold procedures? After all,
> Scheme has such procedures as well (SRFI 1 and R6RS).
(CC'ing the mail list.)
SRFI 1 specifies:
fold kons knil clist1 clist2 ... -> value
The fundamental list iterator.
First, consider the single list-parameter case. If clist1 = (e1 e2
... en), then this procedure returns
(kons en ... (kons e2 (kons e1 knil)) ... )
So kons is called with the elements of the list as the left argument.
The same is true for fold-right.
In SRFI 231, as in Haskell and Ocaml, as I understand it, foldl calls
kons with the list element as the right argument, and foldr calls kons
with the list element as the left argument.
I chose this convention because I was thinking of things like matrix
multiply, which would have a left identity (use array-foldl) and a
different right identity (use array-foldr).
Brad