The type Scanl m a b represents a consumer of an input stream of values
of type a and returning a final value of type b in Monad m. The
constructor of a scan is Scanl step initial extract final.
The scan uses an internal state of type s. The initial value of the state
s is created by initial. This function is called once and only once
before the scan starts consuming input. Any resource allocation can be done
in this function.
The step function is called on each input, it consumes an input and
returns the next intermediate state (see Step) or the final result b if
the scan terminates.
The extract function is used by the scan
driver to map the current state s of the scan to the scan result. Thus
extract can be called multiple times.
Before a scan terminates, final is called once and only once (unless the
scan terminated in initial itself). Any resources allocated by initial
can be released in final. In scan that do not require any cleanup
extract and final are typically the same.
When implementing scan combinators, care should be taken to cleanup any
state of the argument folds held by the fold by calling the respective
final at all exit points of the scan. Also, final should not be called
more than once. Note that if a scan terminates by Done constructor, there
is no state to cleanup.
NOTE: The constructor is not yet released, smart constructors are provided to create scans.