on master help sign in
Document Rel8.Table.These
1a3c3c1Ollie Charles
src/Rel8/Table/These.hs+18
@@ -78,6 +78,13 @@ import Data.Functor.Bind ( Bind, (>>-) )
78import Data.These ( These )
78import Data.These ( These )
79
79
80
80
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'.
85+--
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 {..}
181
188
182
189
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)
185
193
186
194
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
189
198
190
199
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
193
203
194
204
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
197
208
198
209
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
201
213
202
214
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
205
218
206
219
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
209
223
210
224
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
213
228
214
229
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)
217
233
218
234
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)
221
238
222
239
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} =