
Klaus Ostermann wrote:
I am not a Haskell expert, and I am currently exploring type classes and need some advice.
The most important advice is probably to point out that a `class' in Haskell is roughly comparable to an `interface' in Java, but not to a `class'.
class Node n where isConnectedTo :: Graph g n e => g -> n -> e -> Bool
This is not what you want. The type says: "Every node can find out whether it is connected to a given edge _in_any_type_of_graph_", which is clearly impossible given that your Graph class has no methods. Is your setting the notion of being a `Node' only makes sense in connection with a type of `Graph'. The right thing to so is probably to drop the classes `Edge' and `Node' and put their methods into the `Graph' class. class Graph g n e | g -> n e where isConnectedTo :: g -> n -> e -> Bool n1 :: g -> e -> n n2 :: g -> e -> n Udo.