I messed around with some of the Haskell features, some of which I understood, and some not.
For example, if we do: scanl (+) 0 [1..3] , I understand the following:
1. the accumulator is 0 acc = 0 | 2. (+) applied to acc and first el acc = 0 + 1 = 1 | 3. (+) applied to latest acc and snd el acc = 1 + 2 = 3 | 4. (+) applied to latest acc and third acc = 3 + 3 = 6 V
Now, when we create the list, we get [0, 1, 3, 6] .
But I canβt understand how scanr (+) 0 [1..3] gives me: [6,5,3,0] Maybe scanr works as follows?
1. the first element in the list is the sum of all other + acc 2. the second element is the sum from right to left (<-) of the last 2 elements 3. the third element is the sum of first 2...
I do not see if this is a template or not.
source share