Why isn't there a scanl' function in the Haskell standard library?

haskell

Solution

There's no need for it. The strictness of `foldl'` allows it to eliminate thunks immediately as it traverses its input list.

foldl' (+) 0 [1,2,3]           foldl (+)    0                [1,2,3]
foldl' (+) 1 [2,3]             foldl (+)   (0 + 1)           [2,3]
foldl' (+) 3 [3]               foldl (+)  ((0 + 1) + 2)      [3]
foldl' (+) 6 []                foldl (+) (((0 + 1) + 2) + 3) []
6                                        (((0 + 1) + 2) + 3)
                                          ((1 + 2) + 3)
                                           (3 + 3)
                                            6

But when you do `scanl` it produces a list containing each one of those steps

scanl (+) 0 [1,2,3]
[   0
,   0 + 1
,  (0 + 1) + 2
, ((0 + 1) + 2) + 3
]

And you must traverse the entire list to see the final result which lets you control how the thunks are forced. This pushes the control of evaluation to the consumer of the list.

Problem

The `foldl` function comes with a strict analog `foldl'`. Is there a reason why `scanl` doesn't need a `scanl'` alternative or did they simply not include it in the standard library?

Original source