Adding scanl'
Evan Laforge
qdunkan at gmail.com
Tue Sep 11 21:06:28 CEST 2012
On Tue, Sep 11, 2012 at 11:57 AM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
>
> On Tue, 11 Sep 2012, Evan Laforge wrote:
>
>> On Tue, Sep 11, 2012 at 11:43 AM, Henning Thielemann
>> <lemming at henning-thielemann.de> wrote:
>>>
>>> I don't know whether this "scanl'" is of much use. "foldl'" is required
>>> because we can access its accumulator only after "foldl'" finished. But
>>> in
>>> "scanl'" you can and usually should access the interim accumulator values
>>> that are contained in the result list.
>>
>>
>> I use it relatively frequently, e.g. 'intervals = scanl (+) 0 (cycle
>> [2, 1, 2, 2, 1, 2, 2])'
>
>
> And what do you do with the elements of 'intervals'? I guess you consume
> them and then you force their evaluation this way.
Yes, you're right, I don't rely on laziness in the result. And even
if I did, in the case of (+) it probably isn't worth it anyway.
Sorry, I missed that the key point was whether or not the interim
values are used.
More information about the Libraries
mailing list