The situation with Scheme is special here because of how it handles a
varying number of arguments. The existing facilities (lambda rest
arguments, case-lambda, apply, etc.) are all optimized for having the
variadic part of an argument list at the end and not at the front. If
the procedure f just takes the state and the next value of a single
collection, it doesn't matter much from an implementation perspective.
However, as soon as we allow more than one collection to be folded
over (as SRFI 1's fold, for example), it makes a difference.
Am Sa., 12. Sept. 2020 um 23:02 Uhr schrieb John Cowan <xxxxxx@ccil.org>:
>
> Got it, thanks. Not surprising, given that Wadler -> Haskell. In SML both foldl and foldr use new-then-old ordering, i.e. (a * b -> b) -> b -> a list -> b), the same as SRFI 1. In OCaml, however, the order is like Haskell and SRFI 41. So it's not tied to eager vs. lazy, as I first thought.
>
>
> On Sat, Sep 12, 2020 at 3:05 PM Phil Bewig <xxxxxx@gmail.com> wrote:
>>
>> The stream-fold-right in the example is derived from the book by Bird and Wadler, who give this definition:
>>
>> foldr :: (a -> b -> b) -> b -> [a] -> b
>> foldr f a [] = a
>> foldr f a (x : xs) = f x (foldr f a xs)
>>
>> On Sat, Sep 12, 2020 at 2:02 AM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
>>>
>>> So, SRFI 41's fold does it "the right way" (as opposed to SRFI 1's
>>> fold). Why where you interested?
>>>
>>> Am Sa., 12. Sept. 2020 um 00:26 Uhr schrieb John Cowan <xxxxxx@ccil.org>:
>>> >
>>> > Ok, thanks.
>>> >
>>> > On Fri, Sep 11, 2020 at 5:06 PM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
>>> >>
>>> >> According to the documentation of SRFI 41, the state is first when
>>> >> calling f in stream-fold, yes. But we should extend it to more than
>>> >> one stream, of which one has to be finite.
>>> >>
>>> >> stream-fold-right is not provided in the API (the reason is given in
>>> >> SRFI 41), but in one example in SRFI 41. In the example code, it is
>>> >> called with the state (or should I call it "costate" :)) as the second
>>> >> argument.
>>> >>
>>> >> Am Fr., 11. Sept. 2020 um 23:00 Uhr schrieb John Cowan <xxxxxx@ccil.org>:
>>> >> >
>>> >> > Can someone do an analysis of stream-fold and stream-fold-right to say whether what the order of arguments in f is? I am pretty sure the state is called first in stream-fold(-left), but I am uncertain about stream-fold-right.