-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: master
Are you sure you want to change the base?
Conversation
I have fixes for ghc-7.8 but comments still very welcome |
…lways handling maybe
@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. |
It's tough to say whether this belong in |
@RyanGlScott Yeah, that sounds out of scope. Should we close then? |
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.