@@ -66,6 +66,12 @@ import Data.Functor.Apply ( Apply, (<.>) )
6666import Data.Functor.Bind ( Bind, (>>-) )
6767
6868
69+-- | An @EitherTable a b@ is a Rel8 table that contains either the table @a@ or
70+-- the table @b@. You can construct an @EitherTable@ using 'leftTable' and
71+-- 'rightTable', and eliminate/pattern match using 'eitherTable'.
72+--
73+-- An @EitherTable@ is operationally the same as Haskell's 'Either' type, but
74+-- adapted to work with Rel8.
6975type EitherTable :: Type -> Type -> Type
7076data EitherTable a b = EitherTable
7177 { tag :: Tag "isRight" EitherTag
@@ -149,24 +155,30 @@ instance (ToExprs exprs1 a, ToExprs exprs2 b, x ~ EitherTable exprs1 exprs2) =>
149155 bimap (toResult @exprs1) (toResult @exprs2)
150156
151157
158+-- | Test if an 'EitherTable' is a 'leftTable'.
152159isLeftTable :: EitherTable a b -> Expr Bool
153160isLeftTable = isLeft . expr . tag
154161
155162
163+-- | Test if an 'EitherTable' is a 'rightTable'.
156164isRightTable :: EitherTable a b -> Expr Bool
157165isRightTable = isRight . expr . tag
158166
159167
168+-- | Pattern match/eliminate an 'EitherTable', by providing mappings from a
169+-- 'leftTable' and 'rightTable'.
160170eitherTable :: Table Expr c
161171 => (a -> c) -> (b -> c) -> EitherTable a b -> c
162172eitherTable f g EitherTable {tag, left, right} =
163173 bool (f left) (g right) (isRight (expr tag))
164174
165175
176+-- | Construct a left 'EitherTable'. Like 'Left'.
166177leftTable :: Table Expr b => a -> EitherTable a b
167178leftTable a = EitherTable (fromExpr (litExpr IsLeft)) a undefined
168179
169180
181+-- | Construct a right 'EitherTable'. Like 'Right'.
170182rightTable :: Table Expr a => b -> EitherTable a b
171183rightTable = rightTableWith undefined
172184