Skip to content
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 Data.Point containing mpoint, spoint and spoint_ #80

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

code5hot
Copy link

@code5hot code5hot commented Mar 8, 2019

After seeing a reddit thread where someone said you'd have to be mad to want to implement sum without using fold as a justification for keeping it as a member of Foldable I decided to provide a reasonable facility for it which I think justifies not having sum as a member of Foldable.

import Data.Point
import Data.Monoid
import Data.Tree

ipsum :: (InitialPoint p, Functor p, Num a) => p a -> a
ipsum = getSum . mpoint . fmap Sum

t = Node "hello " [Node "world " [Node "foo " [],Node "bar " []], Node "baz " [Node "quux " [], Node "jimbo" []]]
u = length <$> t
c = ipsum u

c is now equal to 34 and the implementation isn't equivalent to fold because the guaranteed associativity of the monoid operation means subtrees can be summed individually and the results summed which also allows for highly parallel summing where fold doesn't allow it.

@code5hot
Copy link
Author

code5hot commented Mar 8, 2019

I have fixes for ghc-7.8 but comments still very welcome

@kozross
Copy link
Contributor

kozross commented Oct 6, 2021

@RyanGlScott Should we considering merging this? I'm happy to do cleanup on it, but I'm not sure if we want it or not.

@RyanGlScott
Copy link
Collaborator

It's tough to say whether this belong in semigroupoids or not. These classes are almost what you'd get if you split of the fold method from Foldable, but they also lack fold's requirement that they be right-associative. Presumably, this is done because there are specific Monoid instances that are designed to exploit parallelism (although I'm not sure what they are off the top of my head).

@kozross
Copy link
Contributor

kozross commented Oct 6, 2021

@RyanGlScott Yeah, that sounds out of scope. Should we close then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants