@@ -40,6 +40,9 @@ import Rel8.Table.Eq ( EqTable )
40import Rel8.Type.Ord ( DBOrd )
40import Rel8.Type.Ord ( DBOrd )
43+-- | The class of 'Table's that can be ordered. Ordering on tables is defined
44+-- by their lexicographic ordering of all columns, so this class means "all
45+-- columns in a 'Table' have an instance of 'DBOrd'".
43type OrdTable :: Type -> Constraint
46type OrdTable :: Type -> Constraint
45 ( EqTable a
48 ( EqTable a
@@ -52,6 +55,8 @@ instance
52instance {-# OVERLAPPING #-} OrdTable Opaque
55instance {-# OVERLAPPING #-} OrdTable Opaque
58+-- | Test if one 'Table' sorts before another. Corresponds to comparing all
55(<:) :: forall a. OrdTable a => a -> a -> Expr Bool
60(<:) :: forall a. OrdTable a => a -> a -> Expr Bool
56(toColumns -> as) <: (toColumns -> bs) =
61(toColumns -> as) <: (toColumns -> bs) =
57 foldr @[] go false $ getConst $ htabulateA $ \field ->
62 foldr @[] go false $ getConst $ htabulateA $ \field ->
@@ -67,6 +72,8 @@ instance {-# OVERLAPPING #-} OrdTable Opaque
75+-- | Test if one 'Table' sorts before, or is equal to, another. Corresponds to
76+-- comparing all columns with '<='.
70(<=:) :: forall a. OrdTable a => a -> a -> Expr Bool
77(<=:) :: forall a. OrdTable a => a -> a -> Expr Bool
71(toColumns -> as) <=: (toColumns -> bs) =
78(toColumns -> as) <=: (toColumns -> bs) =
72 foldr @[] go true $ getConst $ htabulateA $ \field ->
79 foldr @[] go true $ getConst $ htabulateA $ \field ->
@@ -82,6 +89,8 @@ infix 4 <:
82infix 4 <=:
89infix 4 <=:
92+-- | Test if one 'Table' sorts after another. Corresponds to comparing all
85(>:) :: forall a. OrdTable a => a -> a -> Expr Bool
94(>:) :: forall a. OrdTable a => a -> a -> Expr Bool
86(toColumns -> as) >: (toColumns -> bs) =
95(toColumns -> as) >: (toColumns -> bs) =
87 foldr @[] go false $ getConst $ htabulateA $ \field ->
96 foldr @[] go false $ getConst $ htabulateA $ \field ->
@@ -97,6 +106,8 @@ infix 4 <=:
97infix 4 >:
106infix 4 >:
109+-- | Test if one 'Table' sorts after another. Corresponds to comparing all
110+-- columns with '>='.
100(>=:) :: forall a. OrdTable a => a -> a -> Expr Bool
111(>=:) :: forall a. OrdTable a => a -> a -> Expr Bool
101(toColumns -> as) >=: (toColumns -> bs) =
112(toColumns -> as) >=: (toColumns -> bs) =
102 foldr @[] go true $ getConst $ htabulateA $ \field ->
113 foldr @[] go true $ getConst $ htabulateA $ \field ->
@@ -112,9 +123,11 @@ infix 4 >:
112infix 4 >=:
123infix 4 >=:
126+-- | Given two 'Table's, return the table that sorts before the other.
115least :: OrdTable a => a -> a -> a
127least :: OrdTable a => a -> a -> a
116least a b = bool a b (a <: b)
128least a b = bool a b (a <: b)
131+-- | Given two 'Table's, return the table that sorts after the other.
119greatest :: OrdTable a => a -> a -> a
132greatest :: OrdTable a => a -> a -> a
120greatest a b = bool a b (a >: b)
133greatest a b = bool a b (a >: b)