haggle icon indicating copy to clipboard operation
haggle copied to clipboard

Under what conditions can addLabeledEdge fail?

Open kozross opened this issue 4 years ago • 4 comments

According to the docs, addLabeledEdge has the following type:

addLabeledEdge :: (MLabeledEdge g, PrimMonad m, MonadRef m) => 
    g m -> Vertex -> Vertex -> MEdgeLabel g -> m (Maybe Edge) 

Under what conditions will the resulting Maybe Edge be Nothing? Specifically, I assume that, unless both Vertexes are in g m, this will not create an Edge. Am I correct in this assumption?

kozross avatar Feb 12 '20 22:02 kozross

The edge will not be added if either vertex does not exist in the graph. Also, it allows simple graphs to reject duplicate edges if the edge already exists.

travitch avatar Feb 12 '20 22:02 travitch

@travitch Thanks for the fast response!

Based on your response, if I wanted to 'link together' two different graphs using an edge, it seems like I would first need to 'copy over' the vertices and edges of one graph to the other, and then add said edge. Is that correct, or am I missing an easier way?

kozross avatar Feb 12 '20 22:02 kozross

Correct, that is currently the only method for combining graphs. Unlike fgl, there is no monoid instance for merging graphs because vertex creation is tightly-controlled. I could imagine some interesting combinators for merging graphs, but I don't know what would be best or most useful yet.

travitch avatar Feb 12 '20 23:02 travitch

I could imagine some interesting combinators for merging graphs, but I don't know what would be best or most useful yet.

It might be useful to look at what the algebraic-graphs package does.

noughtmare avatar Aug 08 '21 09:08 noughtmare