module Algebra.Graph.Relation.Reflexive (
ReflexiveRelation, fromRelation, toRelation
) where
import Control.DeepSeq
import Algebra.Graph.Relation
import qualified Algebra.Graph.Class as C
newtype ReflexiveRelation a = ReflexiveRelation { fromReflexive :: Relation a }
deriving (Num, NFData)
instance Ord a => Eq (ReflexiveRelation a) where
x == y = toRelation x == toRelation y
instance Ord a => Ord (ReflexiveRelation a) where
compare x y = compare (toRelation x) (toRelation y)
instance (Ord a, Show a) => Show (ReflexiveRelation a) where
show = show . toRelation
instance Ord a => C.Graph (ReflexiveRelation a) where
type Vertex (ReflexiveRelation a) = a
empty = ReflexiveRelation empty
vertex = ReflexiveRelation . vertex
overlay x y = ReflexiveRelation $ fromReflexive x `overlay` fromReflexive y
connect x y = ReflexiveRelation $ fromReflexive x `connect` fromReflexive y
instance Ord a => C.Reflexive (ReflexiveRelation a)
fromRelation :: Relation a -> ReflexiveRelation a
fromRelation = ReflexiveRelation
toRelation :: Ord a => ReflexiveRelation a -> Relation a
toRelation = reflexiveClosure . fromReflexive