My goal is to do things with an intersection graph of shapes. An intersection graph has nodes: shapes in R^n and there is an edge between nodes if they intersect.
In Haskell, one implements a function,
makeIntersectionGraph :: DynGraph g => [Shape] -> g Shape ()
makeIntersectionGraph sh = ... begin with the empty graph and add nodes and edges as you walk
... through all possible intersections
The above compiles and typechecks fine. A simple thing should be to get the nodes of the graph using the labNodes function.
getNodes sh = labNodes (makeIntersectionGraph sh)
Note that the documentation states:
DynGraph: dynamic, extensible graphs. Dynamic graphs inherit all operations from static graphs but also offer operations to extend and change graphs.
and labNodes is a function for the Graph class. So the above should work.
However, I get the error:
No instance for (Graph gr0) arising from a use of `labNodes'
In the expression: labNodes (makeIntersectionGraph es)
In an equation for `makeIntersectionGraphComplete':
makeIntersectionGraphComplete es
= labNodes (makeIntersectionGraph es)
DFN2Graph.hs:346:46:
No instance for (DynGraph gr0)
arising from a use of `makeIntersectionGraph'
In the first argument of `labNodes', namely
`(makeIntersectionGraph es)'
In the expression: labNodes (makeIntersectionGraph es)
In an equation for `makeIntersectionGraphComplete':
makeIntersectionGraphComplete es
= labNodes (makeIntersectionGraph es)
---- Update ---- I found a solution, but I don't understand what the problem is. If I change the type
makeIntersectionGraph :: DynGraph g => [Shape] -> g Shape ()
To
makeIntersectionGraph :: [Shape] -> G.Gr Shape ()
where
import qualified Data.Graph.Inductive.PatriciaTree as G
Then
getNodes sh = labNodes (makeIntersectionGraph sh)
works perfectly fine. The problem I still have is that I don't see why it is necessary to invoke a concrete implementation of a DynGraph when all DynGraphs have access to the same functions.