@@ -37,12 +37,11 @@ import Rel8.Expr ( Expr )
37import Rel8.Expr.Bool ( (&&.), not_ )
37import Rel8.Expr.Bool ( (&&.), not_ )
38import Rel8.Expr.Null ( isNonNull )
38import Rel8.Expr.Null ( isNonNull )
39import Rel8.Schema.Context.Nullify
39import Rel8.Schema.Context.Nullify
40− ( Nullifiable, ConstrainTag
40+ ( Nullifiable
41− , HNullifiable, HConstrainTag
41+ , encodeTag, decodeTag
42− , hencodeTag, hdecodeTag
42+ , nullifier, unnullifier
43− , hnullifier, hunnullifier
45−import Rel8.Schema.HTable ( HTable )
44+import Rel8.Schema.Dict ( Dict( Dict ) )
46import Rel8.Schema.HTable.Label ( hlabel, hunlabel )
45import Rel8.Schema.HTable.Label ( hlabel, hunlabel )
47import Rel8.Schema.HTable.Identity ( HIdentity(..) )
46import Rel8.Schema.HTable.Identity ( HIdentity(..) )
48import Rel8.Schema.HTable.Nullify ( hnullify, hunnullify )
47import Rel8.Schema.HTable.Nullify ( hnullify, hunnullify )
@@ -132,33 +131,82 @@ instance (Table Expr a, Table Expr b, Semigroup a, Semigroup b) =>
134 ( Table context a, Table context b
133 ( Table context a, Table context b
135− , Nullifiable context, ConstrainTag context MaybeTag
134+ , Nullifiable context
136− ) => Table context (TheseTable a b)
136+ => Table context (TheseTable a b)
138 type Columns (TheseTable a b) = HTheseTable (Columns a) (Columns b)
138 type Columns (TheseTable a b) = HTheseTable (Columns a) (Columns b)
139 type Context (TheseTable a b) = Context a
139 type Context (TheseTable a b) = Context a
141− toColumns = toColumns2 toColumns toColumns
141+ toColumns TheseTable {here, there} = HTheseTable
142− fromColumns = fromColumns2 fromColumns fromColumns
142+ { hhereTag = hlabel $ HType $ encodeTag (toHereTag (tag here))
144+ hlabel $ hnullify (nullifier (tag here) isNonNull) $ toColumns $
146+ , hthereTag = hlabel $ HType $ encodeTag (toThereTag (tag there))
148+ hlabel $ hnullify (nullifier (tag there) isNonNull) $ toColumns $
152+ fromColumns HTheseTable {hhereTag, hhere, hthereTag, hthere} = TheseTable
155+ tag = decodeTag $ unHIdentity $ hunlabel hhereTag
162+ hunnullify (\a -> pure . unnullifier a) $
168+ tag = decodeTag $ unHIdentity $ hunlabel hthereTag
175+ hunnullify (\a -> pure . unnullifier a) $
143 reify = liftA2 bimap reify reify
182 reify = liftA2 bimap reify reify
144 unreify = liftA2 bimap unreify unreify
183 unreify = liftA2 bimap unreify unreify
148− ( Nullifiable from, ConstrainTag from MaybeTag
187+ ( Nullifiable from, Nullifiable to
149− , Nullifiable to, ConstrainTag to MaybeTag
150 , Recontextualize from to a1 b1
188 , Recontextualize from to a1 b1
151 , Recontextualize from to a2 b2
189 , Recontextualize from to a2 b2
153− Recontextualize from to (TheseTable a1 a2) (TheseTable b1 b2)
191+ => Recontextualize from to (TheseTable a1 a2) (TheseTable b1 b2)
156instance (EqTable a, EqTable b) => EqTable (TheseTable a b) where
194instance (EqTable a, EqTable b) => EqTable (TheseTable a b) where
157− eqTable = toColumns2 id id (thoseTable (eqTable @a) (eqTable @b))
195+ eqTable = HTheseTable
196+ { hhereTag = hlabel (HType Dict)
197+ , hhere = hlabel (hnullify (\_ Dict -> Dict) (eqTable @a))
198+ , hthereTag = hlabel (HType Dict)
199+ , hthere = hlabel (hnullify (\_ Dict -> Dict) (eqTable @b))
160instance (OrdTable a, OrdTable b) => OrdTable (TheseTable a b) where
203instance (OrdTable a, OrdTable b) => OrdTable (TheseTable a b) where
161− ordTable = toColumns2 id id (thoseTable (ordTable @a) (ordTable @b))
204+ ordTable = HTheseTable
205+ { hhereTag = hlabel (HType Dict)
206+ , hhere = hlabel (hnullify (\_ Dict -> Dict) (ordTable @a))
207+ , hthereTag = hlabel (HType Dict)
208+ , hthere = hlabel (hnullify (\_ Dict -> Dict) (ordTable @b))
164type instance FromExprs (TheseTable a b) = These (FromExprs a) (FromExprs b)
212type instance FromExprs (TheseTable a b) = These (FromExprs a) (FromExprs b)
@@ -275,61 +323,3 @@ nameTheseTable here there a b =
275 { here = nameMaybeTable here a
323 { here = nameMaybeTable here a
276 , there = nameMaybeTable there b
324 , there = nameMaybeTable there b
283− , HConstrainTag context MaybeTag
284− , HNullifiable context
289− -> HTheseTable t u context
290−toColumns2 f g TheseTable {here, there} = HTheseTable
291− { hhereTag = hlabel $ HType $ hencodeTag (toHereTag (tag here))
293− hlabel $ hnullify (hnullifier (tag here) isNonNull) $ f (just here)
294− , hthereTag = hlabel $ HType $ hencodeTag (toThereTag (tag there))
296− hlabel $ hnullify (hnullifier (tag there) isNonNull) $ g (just there)
303− , HConstrainTag context MaybeTag
304− , HNullifiable context
308− -> HTheseTable t u context
310−fromColumns2 f g HTheseTable {hhereTag, hhere, hthereTag, hthere} = TheseTable
313− tag = hdecodeTag $ unHIdentity $ hunlabel hhereTag
319− hunnullify (\a -> pure . hunnullifier a) $
325− tag = hdecodeTag $ unHIdentity $ hunlabel hthereTag
331− hunnullify (\a -> pure . hunnullifier a) $