Defining own Ord for a data type

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 Eq instance; the default one won’t work, as it compares every field. Luckily, this is easy:

instance Eq Edge where
  (Edge s1 _) == (Edge s2 _) = s1 == s2

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:

instance Ord Edge where
  (Edge s1 _) `compare` (Edge s2 _) = s1 `compare` s2

Each type class defines a certain set of methods which need to be implemented; Eq requires == or /=, and Ord requires <= or compare. (To find out which functions are required and which are optional, you can check the docs.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)