
Am Sonntag, 6. November 2005 17:30 schrieb Klaus Ostermann:
Daniel Fischer schrieb:
I'd prefer (very strongly) something like
class Graph g n e | g -> n, g -> e where isConnectedTo :: g -> n -> e -> Bool -- or perhaps rather without "g" startNode, endNode :: e -> n . . . -- other Methods of interest like nodes, edges, components . . .
with, e.g.
instance Graph (Map node [node]) node (node,node) where . . .
Thanks for the suggestion. This looks good, but it seems as if the "g" needs to occur in every signature, otherwise the interpreter throws a "No instance for ... arising from ..." error if you want to apply the function. Hence startNode would need to be startNode :: g -> e -> n rather than startNode :: e -> n
Is there any way to get rid of this dummy argument?
Klaus
Two I see, 1. retain class Edge, class Edge e n | e -> n, n -> e where isConnectedTo :: n -> e -> Bool startNode, endNode :: e -> n and then class (Edge e n) => Graph g n e | g -> n, g -> e where -- other methods if wanted 2. add more FunDeps, class Graph g n e | g -> n, g -> e, e -> n, n -> e, n e -> g where . . . works. Probably the second isn't wanted, because it introduces too much rigidity and an ADT might be better. Cheers, Daniel