
What you need is a Relation, not a Graph with nodes all of the same type! For me the problem below is most easily solved using Data.Map either use Map Person [Hamster] or Map Hamster [Person] to get the most general relations (many-many) If every Hamster has at most one owner, use Map Hamster Person
Jeffrey Brown
writes: I use FGL, which (roughly) defines type Gr a b as a graph on nodes of type a and edges of type b.
Suppose you wanted a graph that described which people own which hamsters, knowing only their name. You would have to make node and edge types like this: data GraphNode = Person String | Hamster String data GraphEdge = Has where the strings represent their names.
Suppose then you wanted to write a function that, given a person, returns the names of all their hamsters. To make sure the call makes sense, the function would have to first check that the input is in fact a person. Since persons and hamsters are both constructors of the same type, you can't let Haskell's robust, beautiful type-checking system distinguish them for you; you've got to write something like "case n of Person _ -> True; _ -> False".
Andrew Butterfield School of Computer Science & Statistics Trinity College Dublin 2, Ireland