@@ -78,6 +78,13 @@ import Data.Functor.Bind ( Bind, (>>-) )
78import Data.These ( These )
78import Data.These ( These )
81+-- | @TheseTable a b@ is a Rel8 table that contains either the table @a@, the
82+-- table @b@, or both tables @a@ and @b@. You can construct @TheseTable@s using
83+-- 'thisTable', 'thatTable' and 'thoseTable'. @TheseTable@s can be
84+-- eliminated/pattern matched using 'theseTable'.
86+-- @TheseTable@ is operationally the same as Haskell's 'These' type, but
87+-- adapted to work with Rel8.
81type TheseTable :: Type -> Type -> Type
88type TheseTable :: Type -> Type -> Type
82data TheseTable a b = TheseTable
89data TheseTable a b = TheseTable
83 { here :: MaybeTable a
90 { here :: MaybeTable a
@@ -180,46 +187,57 @@ toThereTag :: Tag "isJust" a -> Tag "hasThere" a
180toThereTag Tag {..} = Tag {..}
187toThereTag Tag {..} = Tag {..}
190+-- | Test if a 'TheseTable' was constructed with 'thisTable'.
183isThisTable :: TheseTable a b -> Expr Bool
191isThisTable :: TheseTable a b -> Expr Bool
184isThisTable a = hasHereTable a &&. not_ (hasThereTable a)
192isThisTable a = hasHereTable a &&. not_ (hasThereTable a)
195+-- | Test if a 'TheseTable' was constructed with 'thatTable'.
187isThatTable :: TheseTable a b -> Expr Bool
196isThatTable :: TheseTable a b -> Expr Bool
188isThatTable a = not_ (hasHereTable a) &&. hasThereTable a
197isThatTable a = not_ (hasHereTable a) &&. hasThereTable a
200+-- | Test if a 'TheseTable' was constructed with 'thoseTable'.
191isThoseTable :: TheseTable a b -> Expr Bool
201isThoseTable :: TheseTable a b -> Expr Bool
192isThoseTable a = hasHereTable a &&. hasThereTable a
202isThoseTable a = hasHereTable a &&. hasThereTable a
205+-- | Test if the @a@ table of @TheseTable a b@ is present.
195hasHereTable :: TheseTable a b -> Expr Bool
206hasHereTable :: TheseTable a b -> Expr Bool
196hasHereTable TheseTable {here} = isJustTable here
207hasHereTable TheseTable {here} = isJustTable here
210+-- | Test if the @b@ table of @TheseTable a b@ is present.
199hasThereTable :: TheseTable a b -> Expr Bool
211hasThereTable :: TheseTable a b -> Expr Bool
200hasThereTable TheseTable {there} = isJustTable there
212hasThereTable TheseTable {there} = isJustTable there
215+-- | Attempt to project out the @a@ table of a @TheseTable a b@.
203justHereTable :: TheseTable a b -> MaybeTable a
216justHereTable :: TheseTable a b -> MaybeTable a
204justHereTable = here
217justHereTable = here
220+-- | Attempt to project out the @b@ table of a @TheseTable a b@.
207justThereTable :: TheseTable a b -> MaybeTable b
221justThereTable :: TheseTable a b -> MaybeTable b
208justThereTable = there
222justThereTable = there
225+-- | Construct a @TheseTable@. Corresponds to 'This'.
211thisTable :: Table Expr b => a -> TheseTable a b
226thisTable :: Table Expr b => a -> TheseTable a b
212thisTable a = TheseTable (justTable a) nothingTable
227thisTable a = TheseTable (justTable a) nothingTable
230+-- | Construct a @TheseTable@. Corresponds to 'That'.
215thatTable :: Table Expr a => b -> TheseTable a b
231thatTable :: Table Expr a => b -> TheseTable a b
216thatTable b = TheseTable nothingTable (justTable b)
232thatTable b = TheseTable nothingTable (justTable b)
235+-- | Construct a @TheseTable@. Corresponds to 'These'.
219thoseTable :: a -> b -> TheseTable a b
236thoseTable :: a -> b -> TheseTable a b
220thoseTable a b = TheseTable (justTable a) (justTable b)
237thoseTable a b = TheseTable (justTable a) (justTable b)
240+-- | Pattern match on a 'TheseTable'.
223theseTable :: Table Expr c
241theseTable :: Table Expr c
224 => (a -> c) -> (b -> c) -> (a -> b -> c) -> TheseTable a b -> c
242 => (a -> c) -> (b -> c) -> (a -> b -> c) -> TheseTable a b -> c
225theseTable f g h TheseTable {here, there} =
243theseTable f g h TheseTable {here, there} =