haggle
haggle copied to clipboard
Under what conditions can addLabeledEdge fail?
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 Vertex
es are in g m
, this will not create an Edge
. Am I correct in this assumption?
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 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?
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.
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.