Adding scanl'
Henning Thielemann
lemming at henning-thielemann.de
Tue Sep 11 20:57:51 CEST 2012
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.
However, it might be that you filter out some elements and thus consume
only some of the elements. In this case it might be better to have a
"scanl'".
More information about the Libraries
mailing list