module Pandora.Pattern.Object.Chain (Chain (..)) where

import Pandora.Pattern.Object.Setoid (Setoid)
import Pandora.Paradigm.Primary.Object.Boolean (Boolean (True, False))
import Pandora.Paradigm.Primary.Object.Ordering (Ordering, order)

infixl 7 <=>
infixl 8 <=, >=
infixl 9 <, >

{- |
> When providing a new instance, you should ensure it satisfies:
> * Reflexivity: x <= x ≡ True
> * Transitivity: x <= y && y <= z ≡ True ===> x <= z ≡ True
> * Antisymmetry: x <= y && y <= x ≡ True ===> x == y ≡ True
-}

class Setoid a => Chain a where
	{-# MINIMAL (<=>) #-}
	(<=>) :: a -> a -> Ordering

	(<) :: a -> a -> Boolean
	a
x < a
y = Boolean -> Boolean -> Boolean -> Ordering -> Boolean
forall a. a -> a -> a -> Ordering -> a
order Boolean
False Boolean
True Boolean
False (a
x a -> a -> Ordering
forall a. Chain a => a -> a -> Ordering
<=> a
y)
	(<=) :: a -> a -> Boolean
	a
x <= a
y = Boolean -> Boolean -> Boolean -> Ordering -> Boolean
forall a. a -> a -> a -> Ordering -> a
order Boolean
True Boolean
True Boolean
False (a
x a -> a -> Ordering
forall a. Chain a => a -> a -> Ordering
<=> a
y)
	(>) :: a -> a -> Boolean
	a
x > a
y = Boolean -> Boolean -> Boolean -> Ordering -> Boolean
forall a. a -> a -> a -> Ordering -> a
order Boolean
False Boolean
False Boolean
True (a
x a -> a -> Ordering
forall a. Chain a => a -> a -> Ordering
<=> a
y)
	(>=) :: a -> a -> Boolean
	a
x >= a
y = Boolean -> Boolean -> Boolean -> Ordering -> Boolean
forall a. a -> a -> a -> Ordering -> a
order Boolean
True Boolean
False Boolean
True (a
x a -> a -> Ordering
forall a. Chain a => a -> a -> Ordering
<=> a
y)