-
Notifications
You must be signed in to change notification settings - Fork 140
Add generic foldMap #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add generic foldMap #337
Conversation
|
Looks good to me. I don't think we need to dwell too much on explaining these functions since this is the concept from |
|
I'd like to keep this PR for a few days. Maybe I'll come with something better. It's well known concept but I think it worth repeating |
Data/Vector.hs
Outdated
| -- | @since NEXT | ||
| -- /O(n)/ Map each element of the structure to a monoid, and combine | ||
| -- the results. This function is implemented in terms of 'foldr' in | ||
| -- the same way as default implementation in 'Foldable' type class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could avoid refering to implementation details by saying "Map each element of the structure to a monoid, and combine results {lazily,strictly}, similar to Data.Foldable.{foldMap,foldMap'}" or along these lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I removed foldl/foldr mentions as implementation detial. But then decided to restore it. Whether function will fuse or not depends whether foldl/foldr is used. It's unfortunate that implementation details leak like that
6ba0ac5 to
aed3022
Compare
|
I tried and failed to come up with anything better. So I think PR is ready for merge |
Data/Vector/Generic.hs
Outdated
| foldMap' f = foldl' (\acc a -> acc `mappend` f a) mempty | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very minor nitpicking, but you put three empty lines here, two empty lines in Data.Vector and one line elsewhere.
Co-authored-by: Bodigrim <andrew.lelechenko@gmail.com>
|
@Bodigrim fixed everything you mentioned |
Co-authored-by: Bodigrim <andrew.lelechenko@gmail.com>
Fixes #263.
foldMapis implemented in terms offoldrandfoldMap'in terms offoldl'This is draft since I want to make sure that we agree on implementation and documentation and only then do copy-paste work. I certainly don't like haddocks as wrote them. Those are riddles fit for sphinx.
foldMapis useful when one do need laziness but I can't put in words. Suggestions?