Closed meooow25 closed 1 year ago
foldrBits is defined in Data.IntSet.Internal as https://github.com/haskell/containers/blob/f61b0c9104a3c436361f56a0974c5eeef40c1b89/containers/src/Data/IntSet/Internal.hs#L1649-L1653
foldrBits
Data.IntSet.Internal
This is unusual because go traverses the full word, building up thunks, before returning a result. I would expect a foldr to be defined as
go
foldr
go 0 = z go bm = f x (go bm') where x = ... bm' = ...
I don't think this has an effect on correctness, but it might have an effect on performance.
The implementation was introduced in https://github.com/haskell/containers/commit/e076b33f4cee3f657b5bdc5bf6f5a4c9e249d00c, which says
Foldr implementations bit-reverse the word and then iterate from the LSB to MSB using accumulator. That is faster then either not using accumulator or iterating from MSB to LSB.
Which seems a bit odd and worth rechecking in my opinion. Thoughts?
Yes, I completely agree.
Great, happy to take a look at it after I'm done with some of the other PRs here. Don't want to take on too much at once.
I just found #666 which describes this very issue.
foldrBits
is defined inData.IntSet.Internal
as https://github.com/haskell/containers/blob/f61b0c9104a3c436361f56a0974c5eeef40c1b89/containers/src/Data/IntSet/Internal.hs#L1649-L1653This is unusual because
go
traverses the full word, building up thunks, before returning a result. I would expect afoldr
to be defined asI don't think this has an effect on correctness, but it might have an effect on performance.
The implementation was introduced in https://github.com/haskell/containers/commit/e076b33f4cee3f657b5bdc5bf6f5a4c9e249d00c, which says
Which seems a bit odd and worth rechecking in my opinion. Thoughts?