{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE StandaloneDeriving #-}
module OAlg.Structure.PartiallyOrdered.Definition
(
PartiallyOrdered(..), Empty(..), Full(..)
)
where
import OAlg.Prelude
import OAlg.Structure.Oriented.Opposite
class Eq a => PartiallyOrdered a where
infix 4 <<=
(<<=) :: a -> a -> Bool
instance PartiallyOrdered x => PartiallyOrdered (Op x) where Op x
x <<= :: Op x -> Op x -> Bool
<<= Op x
y = x
y x -> x -> Bool
forall a. PartiallyOrdered a => a -> a -> Bool
<<= x
x
instance PartiallyOrdered Bool where
<<= :: Bool -> Bool -> Bool
(<<=) = Bool -> Bool -> Bool
forall a. Ord a => a -> a -> Bool
(<=)
instance Eq x => PartiallyOrdered [x] where
[] <<= :: [x] -> [x] -> Bool
<<= [x]
_ = Bool
True
[x]
_ <<= [] = Bool
False
(x
x:[x]
xs) <<= (x
y:[x]
ys) = case x
x x -> x -> Bool
forall a. Eq a => a -> a -> Bool
== x
y of
Bool
True -> [x]
xs [x] -> [x] -> Bool
forall a. PartiallyOrdered a => a -> a -> Bool
<<= [x]
ys
Bool
False -> (x
xx -> [x] -> [x]
forall a. a -> [a] -> [a]
:[x]
xs) [x] -> [x] -> Bool
forall a. PartiallyOrdered a => a -> a -> Bool
<<= [x]
ys
class PartiallyOrdered a => Empty a where
empty :: a
isEmpty :: a -> Bool
isEmpty a
x = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
forall a. Empty a => a
empty
instance Empty Bool where
empty :: Bool
empty = Bool
False
instance Eq x => Empty [x] where
empty :: [x]
empty = []
isEmpty :: [x] -> Bool
isEmpty [] = Bool
True
isEmpty [x]
_ = Bool
False
class PartiallyOrdered a => Full a where
full :: a
isFull :: a -> Bool
isFull a
x = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
forall a. Full a => a
full
instance Full Bool where
full :: Bool
full = Bool
True