Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: added Compare classes to Ordering #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 60 additions & 4 deletions src/Type/Data/Ordering.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,28 @@ module Type.Data.Ordering
, class Invert
, invert
, class Equals
, equals
, class Compare
, compare
, class IsLt
, isLt
, class IsEq
, isEq
, class IsGt
, isGt
, class IsLte
, isLte
, class IsGte
, isGte
) where

import Prim.Ordering (LT, EQ, GT, Ordering) as PO
import Data.Ordering (Ordering(..))
import Type.Data.Boolean (True, False)
import Type.Proxy (Proxy(..))
import Data.Ordering (Ordering(..))
import Data.Symbol (SProxy)
import Prim.Symbol (class Compare) as Symbol
import Prim.Boolean(True, False)
import Type.Data.Boolean (class Or, BProxy(..))

-- | Value proxy for `Ordering` types
-- | **Deprecated:** Use `Type.Proxy` instead
Expand Down Expand Up @@ -71,5 +86,46 @@ instance equalsLTGT :: Equals PO.LT PO.GT False
instance equalsGTLT :: Equals PO.GT PO.LT False
instance equalsGTEQ :: Equals PO.GT PO.EQ False

equals :: forall proxy l r o. Equals l r o => proxy l -> proxy r -> Proxy o
equals _ _ = Proxy
-- | Compares type a b
class Compare :: forall k. k -> k -> Ordering -> Constraint
class Compare a b (o :: Ordering) | a b -> o

compare :: forall a b o. Compare a b o => a -> b -> OProxy o
compare _ _ = OProxy

class IsLt :: forall k. k -> k -> Boolean -> Constraint
class IsLt a b (isLt :: Boolean) | a b -> isLt
instance isLtTrue ∷ (Compare a b o, Equals o PO.LT isLt) => IsLt a b isLt

isLt :: forall a b isLt. IsLt a b isLt => a -> b -> BProxy isLt
isLt _ _ = BProxy

class IsGt :: forall k. k -> k -> Boolean -> Constraint
class IsGt a b (isGt :: Boolean) | a b -> isGt
instance isGtCompare :: (Compare a b o, Equals o PO.GT isGt) => IsGt a b isGt

isGt :: forall a b isGt. IsGt a b isGt => a -> b -> BProxy isGt
isGt _ _ = BProxy

class IsEq :: forall k. k -> k -> Boolean -> Constraint
class IsEq a b (isEq :: Boolean) | a b -> isEq
instance isEqCompare :: (Compare a b o, Equals o PO.EQ isEq) => IsEq a b isEq

isEq :: forall a b isEq. IsEq a b isEq => a -> b -> BProxy isEq
isEq _ _ = BProxy

class IsLte :: forall k. k -> k -> Boolean -> Constraint
class IsLte a b (isLte :: Boolean) | a b -> isLte
instance isLteFromIs ∷ (IsEq a b isEq, IsLt a b isLt, Or isEq isLt isLte) => IsLte a b isLte

isLte :: forall a b isLte. IsLte a b isLte => a -> b -> BProxy isLte
isLte _ _ = BProxy

class IsGte :: forall k. k -> k -> Boolean -> Constraint
class IsGte a b (isGte :: Boolean) | a b -> isGte
instance isGteFromIs :: (IsEq a b isEq, IsGt a b isGt, Or isEq isGt isGte) => IsGte a b isGte

isGte :: forall a b isGte. IsGte a b isGte => a -> b -> BProxy isGte
isGte _ _ = BProxy

instance compareOrd :: Symbol.Compare lhs rhs ord => Compare (SProxy lhs) (SProxy rhs) ord