@@ -9,13 +9,30 @@ module Type.Data.Ordering
99 , class Invert
1010 , invert
1111 , class Equals
12+ , class Compare
13+ , compare
14+ , class IsLt
15+ , isLt
16+ , class IsEq
17+ , isEq
18+ , class IsGt
19+ , isGt
20+ , class IsLte
21+ , isLte
22+ , class IsGte
23+ , isGte
1224 , equals
1325 ) where
1426
1527import Prim.Ordering (LT , EQ , GT , Ordering ) as PO
1628import Data.Ordering (Ordering (..))
1729import Type.Data.Boolean (True , False )
1830import Type.Proxy (Proxy (..))
31+ import Data.Ordering (Ordering (..))
32+ import Data.Symbol (SProxy )
33+ import Prim.Ordering (Ordering , LT , EQ , GT )
34+ import Prim.Symbol (class Compare ) as Symbol
35+ import Type.Data.Boolean (class Or , BProxy (..), False , True , Boolean )
1936
2037-- | Value proxy for `Ordering` types
2138-- | **Deprecated:** Use `Type.Proxy` instead
@@ -71,5 +88,40 @@ instance equalsLTGT :: Equals PO.LT PO.GT False
7188instance equalsGTLT :: Equals PO.GT PO.LT False
7289instance equalsGTEQ :: Equals PO.GT PO.EQ False
7390
74- equals :: forall proxy l r o . Equals l r o => proxy l -> proxy r -> Proxy o
75- equals _ _ = Proxy
91+ -- | Compares type a b
92+ class Compare a b (o :: Ordering ) | a b -> o
93+
94+ compare :: forall a b o . Compare a b o => a -> b -> OProxy o
95+ compare _ _ = OProxy
96+
97+ class IsLt a b (isLt :: Boolean ) | a b -> isLt
98+ instance isLtTrue ∷ (Compare a b o , Equals o LT isLt ) => IsLt a b isLt
99+
100+ isLt :: forall a b isLt . IsLt a b isLt => a -> b -> BProxy isLt
101+ isLt _ _ = BProxy
102+
103+ class IsGt a b (isGt :: Boolean ) | a b -> isGt
104+ instance isGtCompare :: (Compare a b o , Equals o GT isGt ) => IsGt a b isGt
105+
106+ isGt :: forall a b isGt . IsGt a b isGt => a -> b -> BProxy isGt
107+ isGt _ _ = BProxy
108+
109+ class IsEq a b (isEq :: Boolean ) | a b -> isEq
110+ instance isEqCompare :: (Compare a b o , Equals o EQ isEq ) => IsEq a b isEq
111+
112+ isEq :: forall a b isEq . IsEq a b isEq => a -> b -> BProxy isEq
113+ isEq _ _ = BProxy
114+
115+ class IsLte a b (isLte :: Boolean ) | a b -> isLte
116+ instance isLteFromIs ∷ (IsEq a b isEq , IsLt a b isLt , Or isEq isLt isLte ) => IsLte a b isLte
117+
118+ isLte :: forall a b isLte . IsLte a b isLte => a -> b -> BProxy isLte
119+ isLte _ _ = BProxy
120+
121+ class IsGte a b (isGte :: Boolean ) | a b -> isGte
122+ instance isGteFromIs :: (IsEq a b isEq , IsGt a b isGt , Or isEq isGt isGte ) => IsGte a b isGte
123+
124+ isGte :: forall a b isGte . IsGte a b isGte => a -> b -> BProxy isGte
125+ isGte _ _ = BProxy
126+
127+ instance compareOrd :: Symbol.Compare lhs rhs ord => Compare (SProxy lhs ) (SProxy rhs ) ord
0 commit comments