Improve `Foldable` instance for `Array`
authorDavid Feuer <David.Feuer@gmail.com>
Thu, 13 Nov 2014 08:10:57 +0000 (09:10 +0100)
committerHerbert Valerio Riedel <hvr@gnu.org>
Thu, 13 Nov 2014 08:16:49 +0000 (09:16 +0100)
commit212a350547e950cc5be465a3d76e346ef14bf2ab
tree61453d586c8ed748522fa4c62b51a0fbcf01ba6a
parentc016e6f74e26708586352fec657798f271b0675b
Improve `Foldable` instance for `Array`

Previously, `Array`s were simply converted to lists, and the list
methods used. That works acceptably well for `foldr` and `foldr1`, but
not so sensibly for most other things. Left folds ended up "twisted" the
way they are for lists, leading to surprising performance
characteristics.

Moreover, this implements `length` and `null` so they check the array
size directly.

Finally, a test is added to the testsuite ensuring the overridden
`Foldable` methods agree with their expected default semantics.

Addresses #9763

Reviewed By: hvr, austin

Differential Revision: https://phabricator.haskell.org/D459
libraries/base/Data/Foldable.hs
libraries/base/GHC/Arr.hs
libraries/base/tests/all.T
libraries/base/tests/foldableArray.hs [new file with mode: 0644]
libraries/base/tests/foldableArray.stdout [new file with mode: 0644]