I am attempting to make some data structures to solve a graph puzzle. I am trying to define an edge’s comparison criteria, but I am not sure how. So far:
data Edge = Edge (Set String) Bool
How can I ‘inform’ the compiler that I want edges to be declared equal if they have identical sets of strings, and not have equality have anything to do with the boolean value?
Although I’m not sure why you want to ignore the boolean value (I’m curious), to do so you’ll have to define your own
Eqinstance; the default one won’t work, as it compares every field. Luckily, this is easy:If you want to be able to order edges, and you want the ordering to compare just the sets too, your implementation is very similar:
Each type class defines a certain set of methods which need to be implemented;
Eqrequires==or/=, andOrdrequires<=orcompare. (To find out which functions are required and which are optional, you can check the docs.)