@@ -66,6 +66,12 @@ import Data.Functor.Apply ( Apply, (<.>) )
66import Data.Functor.Bind ( Bind, (>>-) )
66import Data.Functor.Bind ( Bind, (>>-) )
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'.
73+-- An @EitherTable@ is operationally the same as Haskell's 'Either' type, but
74+-- adapted to work with Rel8.
69type EitherTable :: Type -> Type -> Type
75type EitherTable :: Type -> Type -> Type
70data EitherTable a b = EitherTable
76data EitherTable a b = EitherTable
71 { tag :: Tag "isRight" EitherTag
77 { tag :: Tag "isRight" EitherTag
@@ -149,24 +155,30 @@ instance (ToExprs exprs1 a, ToExprs exprs2 b, x ~ EitherTable exprs1 exprs2) =>
149 bimap (toResult @exprs1) (toResult @exprs2)
155 bimap (toResult @exprs1) (toResult @exprs2)
158+-- | Test if an 'EitherTable' is a 'leftTable'.
152isLeftTable :: EitherTable a b -> Expr Bool
159isLeftTable :: EitherTable a b -> Expr Bool
153isLeftTable = isLeft . expr . tag
160isLeftTable = isLeft . expr . tag
163+-- | Test if an 'EitherTable' is a 'rightTable'.
156isRightTable :: EitherTable a b -> Expr Bool
164isRightTable :: EitherTable a b -> Expr Bool
157isRightTable = isRight . expr . tag
165isRightTable = isRight . expr . tag
168+-- | Pattern match/eliminate an 'EitherTable', by providing mappings from a
169+-- 'leftTable' and 'rightTable'.
160eitherTable :: Table Expr c
170eitherTable :: Table Expr c
161 => (a -> c) -> (b -> c) -> EitherTable a b -> c
171 => (a -> c) -> (b -> c) -> EitherTable a b -> c
162eitherTable f g EitherTable {tag, left, right} =
172eitherTable f g EitherTable {tag, left, right} =
163 bool (f left) (g right) (isRight (expr tag))
173 bool (f left) (g right) (isRight (expr tag))
176+-- | Construct a left 'EitherTable'. Like 'Left'.
166leftTable :: Table Expr b => a -> EitherTable a b
177leftTable :: Table Expr b => a -> EitherTable a b
167leftTable a = EitherTable (fromExpr (litExpr IsLeft)) a undefined
178leftTable a = EitherTable (fromExpr (litExpr IsLeft)) a undefined
181+-- | Construct a right 'EitherTable'. Like 'Right'.
170rightTable :: Table Expr a => b -> EitherTable a b
182rightTable :: Table Expr a => b -> EitherTable a b
171rightTable = rightTableWith undefined
183rightTable = rightTableWith undefined