[plt-scheme] implementation of foldl

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Apr 29 16:08:31 EDT 2009

Part (chapter) VI, How to Design Programs.


On Apr 29, 2009, at 3:59 PM, keydana at gmx.de wrote:

> Hi Matthias,
>
> thanks for the explanation. Could you perhaps indicate to me where  
> I could read about this - design styles I mean, regarding induction/ 
> strong induction it's clear :-)
>
> Thanks,
> Sigrid
>
>
>
>
> Am 29.04.2009 um 16:46 schrieb Matthias Felleisen:
>
>>
>> The difference between foldr and foldl is a truly semantic  
>> difference. The latter uses the argument as an accumulator, which  
>> is a "stronger" design style than direct design (i.e. foldr). The  
>> difference is approximately like the one between strong induction  
>> and induction.
>>
>> -- Matthias
>>
>>
>>
>>
>>
>> On Apr 29, 2009, at 10:38 AM, keydana at gmx.de wrote:
>>
>>> Hi Thomas,
>>>
>>> thanks for your answer.
>>>
>>>>
>>>> Maybe the interface is simply designed this way because it  
>>>> matches the
>>>> signature of cons used as a list constructor naturally.
>>>
>>>
>>> That's right, I somehow was mislead by the graphic order of cons'  
>>> arguments, I thought Haskell's way was more intuitive, but it's  
>>> the inverse ...
>>> Might be interesting to know if this really was the reason it was  
>>> implemented like that!
>>>
>>> In general, I would be curious to know if the following picture  
>>> of fold usage in scheme would be approximately correct:
>>>
>>> - for small lists, if a function can be written with foldl and  
>>> foldlr, choose whichever
>>> - more functions can only be written with with foldr because they  
>>> need the empty list at the end
>>> - for very long lists, better use foldl because it uses tail calls
>>>
>>> Ciao,
>>> Sigrid
>>>
>>>
>>>
>>>> However I
>>>> don't see any big advantage of that design. On the contrary it  
>>>> makes
>>>> the implementation of the variadic versions of fold and fold- 
>>>> right a
>>>> little more complicated to pass the initial / accumulator argument
>>>> last instead of first.
>>>>
>>>> cu,
>>>> Thomas
>>>>
>>>>
>>>> -- 
>>>> When C++ is your hammer, every problem looks like your thumb.
>>>
>>> _________________________________________________
>>> For list-related administrative tasks:
>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>



Posted on the users mailing list.