1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 06:41:45 +03:00

Define an Ord instance.

This commit is contained in:
Rob Rix 2018-05-11 12:11:49 -04:00
parent 869b054f2b
commit 6278126f6a

View File

@ -25,3 +25,15 @@ instance Semigroup (Graph v) where
instance Monoid (Graph v) where instance Monoid (Graph v) where
mempty = Class.empty mempty = Class.empty
mappend = (<>) mappend = (<>)
instance Ord v => Ord (Graph v) where
compare (Graph G.Empty) (Graph G.Empty) = EQ
compare (Graph G.Empty) _ = LT
compare _ (Graph G.Empty) = GT
compare (Graph (G.Vertex a)) (Graph (G.Vertex b)) = compare a b
compare (Graph (G.Vertex _)) _ = LT
compare _ (Graph (G.Vertex _)) = GT
compare (Graph (G.Overlay a1 a2)) (Graph (G.Overlay b1 b2)) = (compare `on` Graph) a1 b1 <> (compare `on` Graph) a2 b2
compare (Graph (G.Overlay _ _)) _ = LT
compare _ (Graph (G.Overlay _ _)) = GT
compare (Graph (G.Connect a1 a2)) (Graph (G.Connect b1 b2)) = (compare `on` Graph) a1 b1 <> (compare `on` Graph) a2 b2