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

Remove foldable #121

Merged
merged 15 commits into from
Oct 6, 2018
Merged

Remove foldable #121

merged 15 commits into from
Oct 6, 2018

Conversation

nobrakal
Copy link
Contributor

This is related to #95

So:

  • It removes Foldable and Traversable instance from concerned Graph data-types.
  • It removes comments related to Foldable instances.
  • It drops isEmpty, hasVertex, vertexCount, vertexList, vertexSet, vertexIntSet and box from Algebra.Graph.HigherKinded.Class because of the removal of the Foldable constraint. mesh and torus were rewrited without box.
  • I don't really know what is happening in Algebra.Graph.Labelled but I had to add a foldgUnDiff and a real hasVertex (because elem was used previously).
  • I added a comment related to the Foldable instance in Algebra.Graph.ToGraph (I don't know if it is in the right module).


The 'size' of any graph is positive, and the difference @('size' g - 'length' g)@
corresponds to the number of occurrences of 'empty' in an expression @g@.
Note that 'size' count all leaves of the expression.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"count" -> "counts"

Also, I think we can keep size-related examples above, and replace length examples by vertexCount examples.

-- foldg 1 (const 1) (+) (+) == 'size'
-- foldg True (const False) (&&) (&&) == 'isEmpty'
-- foldg False ((==) v) (||) (||) == 'hasVertex v'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's switch to foldg False (==x) (||) (||) == hasVertex x to match the testsuite as well as actual hasVertex implementation.

ys = map (\a -> fmap (a,) y) $ toList x
xs = map (\b -> fmap (,b) x) $ toListGr y
ys = map (\a -> fmap (a,) y) $ toListGr x
toListGr = foldg [] pure (++) (++)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to use the name toList since the function is equivalent to the standard toList.

By the way, are you sure this is fast enough? Do we need to worry about potential quadratic list concatenation?

You might want to use Algebra.Graph.Internal.List instead to achieve constant-time list concatenation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it is better !


The 'size' of any graph is positive, and the difference @('size' g - 'length' g)@
corresponds to the number of occurrences of 'empty' in an expression @g@.
Note that 'size' count all leaves of the expression.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-- foldg 1 (const 1) (+) (+) == 'size'
-- foldg True (const False) (&&) (&&) == 'isEmpty'
-- foldg False ((==) v) (||) (||) == 'hasVertex v'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-- 'overlay' (stars xs) (stars ys) == stars (xs ++ ys)
-- @
stars :: Graph g => [(a, [a])] -> g a
stars = overlays . map (uncurry star)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it also make sense to switch to your better overlays implementation based on foldr1Safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, I think yes ! I will do some benchs tomorrow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmhh, I spoke too quickly, the concatg solution seems to not work, at least not out-of-the-box...
It will certainly require further work, maybe this is linked with the same problem in Algebra.Graph.Fold

-- foldgUnDiff True (const False) (&&) == 'isEmpty'
-- foldgUnDiff False ((==) v) (||) == 'hasVertex v'
-- @
foldgUnDiff :: b -> (a -> b) -> (b -> b -> b) -> Graph e a -> b
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not make any changes to this module in this PR -- I've got a big refactoring of labelled graphs in a local branch where I implemented a similar fold function and removed Foldable -- I'll make the corresponding PR soon.

The 'size' of any graph is positive and coincides with the result of 'length'
method of the 'Foldable' type class. We define 'size' only for the consistency
with the API of other graph representations, such as "Algebra.Graph".
Note that 'size' count all leaves of the expression.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snowleopard
Copy link
Owner

@nobrakal Many thanks! I left some comments above, but looks good in general.

I don't really know what is happening in Algebra.Graph.Labelled

Let's not do anything about it in this PR -- I've already removed Foldable in my local branch and will push it soon.

@snowleopard
Copy link
Owner

snowleopard commented Sep 23, 2018

@nobrakal Here is the PR on edge-labelled graphs: #122.

@snowleopard
Copy link
Owner

@nobrakal Is this ready or do you plan to do any more work?

@nobrakal
Copy link
Contributor Author

I think this is ready. The stars issue is certainly linked to other things, I will have a look at it later :)

@snowleopard
Copy link
Owner

@nobrakal Thanks, I'll merge it in a couple of days -- want to have another look, but currently travelling!

@snowleopard snowleopard merged commit 7cfbfe8 into snowleopard:master Oct 6, 2018
@snowleopard
Copy link
Owner

@nobrakal Thanks again, merged!

@nobrakal nobrakal deleted the removeFoldable branch October 6, 2018 13:54
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.

2 participants