module Data.POrder where
import Data.Monoid
import qualified Data.Set as S
import Numeric.Natural
import Data.Function
class POrder a where
eqOfLe :: a -> a -> Bool
class Bottom a where bottom :: a
class POrder a => Top a where top :: a
instance POrder a => POrder (Dual a) where
eqOfLe :: Dual a -> Dual a -> Bool
eqOfLe (Dual a
x) (Dual a
y) = a -> a -> Bool
forall a. POrder a => a -> a -> Bool
eqOfLe a
y a
x
instance Top a => Bottom (Dual a) where bottom :: Dual a
bottom = a -> Dual a
forall a. a -> Dual a
Dual a
forall a. Top a => a
top
instance POrder Bool where eqOfLe :: Bool -> Bool -> Bool
eqOfLe = Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
(==)
instance Bottom Bool where bottom :: Bool
bottom = Bool
False
instance Top Bool where top :: Bool
top = Bool
True
instance POrder (S.Set a) where eqOfLe :: Set a -> Set a -> Bool
eqOfLe = Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Int -> Int -> Bool) -> (Set a -> Int) -> Set a -> Set a -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Set a -> Int
forall a. Set a -> Int
S.size
instance Bottom (S.Set a) where bottom :: Set a
bottom = Set a
forall a. Set a
S.empty
instance POrder Natural where eqOfLe :: Natural -> Natural -> Bool
eqOfLe = Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==)
instance Bottom Natural where bottom :: Natural
bottom = Natural
0
instance POrder a => POrder (Maybe a) where
eqOfLe :: Maybe a -> Maybe a -> Bool
eqOfLe Maybe a
Nothing Maybe a
Nothing = Bool
True
eqOfLe Maybe a
Nothing (Just a
_) = Bool
False
eqOfLe (Just a
x) (Just a
y) = a -> a -> Bool
forall a. POrder a => a -> a -> Bool
eqOfLe a
x a
y
eqOfLe (Just a
_) Maybe a
Nothing = [Char] -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"eqOfLe/Maybe used with unrelated arguments"
instance POrder a => Bottom (Maybe a) where bottom :: Maybe a
bottom = Maybe a
forall a. Maybe a
Nothing