#14785 closed bug (fixed)

accumArray is too lazy

Reported by: dfeuer Owned by:
Priority: normal Milestone: 8.6.1
Component: Core Libraries Version: 8.2.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4403
Wiki Page:


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 strictness is desirable, because it prevents thunks from accumulating when we use the passed function. But the strictness isn't actually there! We never force the result of the function.

I believe we should fix the code (and documentation) to maintain the invariant that all elements in the result of accumArray are in WHNF.

Change History (3)

comment:1 Changed 11 months ago by dfeuer

Differential Rev(s): Phab:D4403
Status: newpatch

I have emailed the libraries list and the CLC. In the mean time, I've uploaded a differential.

comment:2 Changed 11 months ago by Ben Gamari <ben@…>

In 08345bd/ghc:

Make accumArray and accum stricter

`accumArray` was lazier than documented. `accum` did not have
documented strictness. The extra laziness allowed thunks to build
up in the array. Force the results of applying the accumulating
function to resolve.

Reviewers: hvr, bgamari

Reviewed By: bgamari

Subscribers: alpmestan, rwbarton, thomie, carter

GHC Trac Issues: #14785

Differential Revision: https://phabricator.haskell.org/D4403

comment:3 Changed 11 months ago by bgamari

Resolution: fixed
Status: patchclosed
Note: See TracTickets for help on using tickets.