@@ -9,12 +9,26 @@ module Type.Data.Ordering
9
9
, class Invert
10
10
, invert
11
11
, 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
12
24
, equals
13
25
) where
14
26
15
- import Prim.Ordering (kind Ordering , LT , EQ , GT )
16
27
import Data.Ordering (Ordering (..))
17
- import Type.Data.Boolean (kind Boolean , True , False , BProxy (..))
28
+ import Data.Symbol (SProxy )
29
+ import Prim.Ordering (kind Ordering , LT , EQ , GT )
30
+ import Prim.Symbol (class Compare ) as Symbol
31
+ import Type.Data.Boolean (class Or , BProxy (..), False , True , kind Boolean )
18
32
19
33
-- | Value proxy for `Ordering` types
20
34
data OProxy (ordering :: Ordering ) = OProxy
@@ -75,3 +89,40 @@ instance equalsGTEQ :: Equals GT EQ False
75
89
equals :: forall l r o . Equals l r o => OProxy l -> OProxy r -> BProxy o
76
90
equals _ _ = BProxy
77
91
92
+ -- | Compares type a b
93
+ class Compare a b (o :: Ordering ) | a b -> o
94
+
95
+ compare :: forall a b o . Compare a b o => a -> b -> OProxy o
96
+ compare _ _ = OProxy
97
+
98
+ class IsLt a b (isLt :: Boolean ) | a b -> isLt
99
+ instance isLtTrue ∷ (Compare a b o , Equals o LT isLt ) => IsLt a b isLt
100
+
101
+ isLt :: forall a b isLt . IsLt a b isLt => a -> b -> BProxy isLt
102
+ isLt _ _ = BProxy
103
+
104
+ class IsGt a b (isGt :: Boolean ) | a b -> isGt
105
+ instance isGtCompare :: (Compare a b o , Equals o GT isGt ) => IsGt a b isGt
106
+
107
+ isGt :: forall a b isGt . IsGt a b isGt => a -> b -> BProxy isGt
108
+ isGt _ _ = BProxy
109
+
110
+ class IsEq a b (isEq :: Boolean ) | a b -> isEq
111
+ instance isEqCompare :: (Compare a b o , Equals o EQ isEq ) => IsEq a b isEq
112
+
113
+ isEq :: forall a b isEq . IsEq a b isEq => a -> b -> BProxy isEq
114
+ isEq _ _ = BProxy
115
+
116
+ class IsLte a b (isLte :: Boolean ) | a b -> isLte
117
+ instance isLteFromIs ∷ (IsEq a b isEq , IsLt a b isLt , Or isEq isLt isLte ) => IsLte a b isLte
118
+
119
+ isLte :: forall a b isLte . IsLte a b isLte => a -> b -> BProxy isLte
120
+ isLte _ _ = BProxy
121
+
122
+ class IsGte a b (isGte :: Boolean ) | a b -> isGte
123
+ instance isGteFromIs :: (IsEq a b isEq , IsGt a b isGt , Or isEq isGt isGte ) => IsGte a b isGte
124
+
125
+ isGte :: forall a b isGte . IsGte a b isGte => a -> b -> BProxy isGte
126
+ isGte _ _ = BProxy
127
+
128
+ instance compareOrd :: Symbol.Compare lhs rhs ord => Compare (SProxy lhs ) (SProxy rhs ) ord
0 commit comments