module Data.Poset.Internal where
import Data.Monoid
data PosetOrd = Comp Ordering | NComp
deriving (Eq, Show, Read)
instance Bounded PosetOrd where
minBound = Comp $ minBound
maxBound = NComp
instance Enum PosetOrd where
toEnum n | n >= 0 && n < 3 = Comp $ toEnum n
| n == 3 = NComp
| otherwise = error "Data.Poset.toEnum: bad argument"
fromEnum (Comp c) = fromEnum c
fromEnum NComp = 3
instance Monoid PosetOrd where
mempty = Comp EQ
mappend (Comp EQ) x = x
mappend NComp _ = NComp
mappend (Comp LT) _ = Comp LT
mappend (Comp GT) _ = Comp GT
partialOrder :: Ordering -> PosetOrd
partialOrder = Comp
class Eq a => Poset a where
posetCmp :: a -> a -> PosetOrd
(<==>) :: a -> a -> Bool
(</=>) :: a -> a -> Bool
leq :: a -> a -> Bool
geq :: a -> a -> Bool
lt :: a -> a -> Bool
gt :: a -> a -> Bool
a `posetCmp` b
| a == b = Comp EQ
| a `leq` b = Comp LT
| b `leq` a = Comp GT
| otherwise = NComp
a <==> b = a `posetCmp` b /= NComp
a </=> b = a `posetCmp` b == NComp
a `lt` b = a `posetCmp` b == Comp LT
a `gt` b = a `posetCmp` b == Comp GT
a `leq` b | a <==> b = a `posetCmp` b /= Comp GT
| otherwise = False
a `geq` b | a <==> b = a `posetCmp` b /= Comp LT
| otherwise = False
infixl 4 <==>,</=>