Proposal: accum and accumArray strictness

David Feuer david.feuer at gmail.com
Fri Feb 9 20:52:32 UTC 2018


The documentation for accumArray is currently broken [*]. According to
the documentation:

According to the documentation,

> If the accumulating function is strict, then 'accumArray' is strict in
> the values, as well as the indices, in the association list.  Thus,
> unlike ordinary arrays built with 'array', accumulated arrays should
> not in general be recursive.

I believe that purported strictness is desirable, because it prevents
thunks from accumulating when we use the passed function. But the
strictness *isn't really there*. accumArray never forces any values
whatsoever! The same is true of accum, but that function does not
document its strictness.

I propose that we change both the implementation and documentation.

For accumArray, I think we should say that the resulting array is
strict in the initial value and in each result of applying the
accumulating function, and indicate that each element of the resulting
array will be in WHNF.

For accum, I think we should say that the resulting array is strict in
each value in the initial array and in each result of applying the
accumulating function, and indicate that each element of the resulting
array will be in WHNF.

We thereby guarantee that we can accumulate strictly, which is
important for performance, and I think being strict in the initial
value(s) makes for simpler reasoning than only being strict in the
results of the combining function.

[*] https://ghc.haskell.org/trac/ghc/ticket/14785

David Feuer


More information about the Libraries mailing list