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
Showing
- libraries/base/Data/Foldable.hs 13 additions, 5 deletionslibraries/base/Data/Foldable.hs
- libraries/base/GHC/Arr.hs 58 additions, 1 deletionlibraries/base/GHC/Arr.hs
- libraries/base/tests/all.T 1 addition, 0 deletionslibraries/base/tests/all.T
- libraries/base/tests/foldableArray.hs 129 additions, 0 deletionslibraries/base/tests/foldableArray.hs
- libraries/base/tests/foldableArray.stdout 13 additions, 0 deletionslibraries/base/tests/foldableArray.stdout
Loading
Please register or sign in to comment