on master help sign in
Remove Labelable type class; we don't really need labels at the type level anymore (#76)
commit4aa5ba952cb607dd806d00886ee677d87436b91c authorShane <shane.obrien@circuithub.com> dateThu 24 Jun 2021, 11:13 (5 years ago) parent70ce05d
34 files changed+273−510
rel8.cabal−2 src/Rel8.hs−2 src/Rel8/Aggregate.hs+1−7 src/Rel8/Column.hs+6−6 src/Rel8/Expr.hs+1−7 src/Rel8/Generic/Construction/ADT.hs+23−31 src/Rel8/Generic/Construction/Record.hs+3−8 src/Rel8/Generic/Rel8able.hs+4−5 src/Rel8/Generic/Table.hs+4−4 src/Rel8/Generic/Table/ADT.hs+14−17 src/Rel8/Generic/Table/Record.hs+6−12 src/Rel8/Kind/Context.hs−12 src/Rel8/Kind/Labels.hs−57 src/Rel8/Schema/Context/Label.hs−62 src/Rel8/Schema/Context/Nullify.hs+16−17 src/Rel8/Schema/HTable/Either.hs+2−3 src/Rel8/Schema/HTable/Identity.hs+2−2 src/Rel8/Schema/HTable/Label.hs+27−52 src/Rel8/Schema/HTable/Maybe.hs+2−3 src/Rel8/Schema/HTable/Nullify.hs+17−17 src/Rel8/Schema/HTable/These.hs+3−4 src/Rel8/Schema/HTable/Vectorize.hs+15−21 src/Rel8/Schema/Name.hs+1−7 src/Rel8/Schema/Reify.hs−6 src/Rel8/Schema/Result.hs+14−22 src/Rel8/Schema/Spec.hs+6−12 src/Rel8/Schema/Spec/ConstrainDBType.hs+14−14 src/Rel8/Table.hs+27−34 src/Rel8/Table/Either.hs+9−15 src/Rel8/Table/Maybe.hs+8−13 src/Rel8/Table/Name.hs+6−2 src/Rel8/Table/Recontextualize.hs+23−6 src/Rel8/Table/Rel8able.hs+8−11 src/Rel8/Table/These.hs+11−17
rel8.cabal−2
@@ -79,7 +79,6 @@ library
7979
8080 Rel8.Kind.Algebra
8181 Rel8.Kind.Context
82− Rel8.Kind.Labels
8382
8483 Rel8.Generic.Construction
8584 Rel8.Generic.Construction.ADT
@@ -115,7 +114,6 @@ library
115114 Rel8.Query.Values
116115
117116 Rel8.Schema.Context
118− Rel8.Schema.Context.Label
119117 Rel8.Schema.Context.Nullify
120118 Rel8.Schema.Dict
121119 Rel8.Schema.HTable
src/Rel8.hs−2
@@ -270,7 +270,6 @@ module Rel8
270270 , evaluate
271271
272272 -- * Implementation details
273− , Labelable
274273 , HKDT(..)
275274 ) where
276275
@@ -317,7 +316,6 @@ import Rel8.Query.SQL (showQuery)
317316import Rel8.Query.Set
318317import Rel8.Query.These
319318import Rel8.Query.Values
320−import Rel8.Schema.Context.Label
321319import Rel8.Schema.HTable
322320import Rel8.Schema.Name
323321import Rel8.Schema.Null hiding ( nullable )
src/Rel8/Aggregate.hs+1−7
@@ -33,7 +33,6 @@ import qualified Opaleye.Internal.PackMap as Opaleye
3333-- rel8
3434import Rel8.Expr ( Expr )
3535import Rel8.Schema.Context ( Interpretation(..) )
36−import Rel8.Schema.Context.Label ( Labelable(..) )
3736import Rel8.Schema.HTable.Identity ( HIdentity(..), HType )
3837import Rel8.Schema.Name ( Name )
3938import Rel8.Schema.Null ( Sql )
@@ -62,7 +61,7 @@ instance Interpretation Aggregate where
6261 data Col Aggregate _spec where
6362 A :: ()
6463 => { unA :: !(Aggregate a) }
65− -> Col Aggregate ('Spec labels a)
64+ -> Col Aggregate ('Spec a)
6665
6766
6867instance Sql DBType a => Table Aggregate (Aggregate a) where
@@ -104,11 +103,6 @@ instance Sql DBType a =>
104103 Recontextualize Name Aggregate (Name a) (Aggregate a)
105104
106105
107−instance Labelable Aggregate where
108− labeler (A aggregate) = A aggregate
109− unlabeler (A aggregate) = A aggregate
110−
111−
112106-- | @Aggregates a b@ means that the columns in @a@ are all 'Aggregate' 'Expr's
113107-- for the columns in @b@.
114108type Aggregates :: Type -> Type -> Constraint
src/Rel8/Column.hs+6−6
@@ -20,7 +20,7 @@ import Rel8.Aggregate ( Aggregate, Col( A ) )
2020import Rel8.Expr ( Expr, Col( E ) )
2121import Rel8.FCF ( Eval, Exp )
2222import Rel8.Kind.Context ( SContext(..), Reifiable( contextSing ) )
23−import Rel8.Schema.HTable.Identity ( HIdentity( HIdentity ) )
23+import Rel8.Schema.HTable.Identity ( HIdentity(..), HType )
2424import qualified Rel8.Schema.Kind as K
2525import Rel8.Schema.Name ( Name(..), Col( N ) )
2626import Rel8.Schema.Null ( Sql )
@@ -55,11 +55,11 @@ instance (Reifiable context, Sql DBType a) =>
5555 Table (Reify context) (AColumn context a)
5656 where
5757 type Context (AColumn context a) = Reify context
58− type Columns (AColumn context a) = HIdentity ('Spec '[] a)
58+ type Columns (AColumn context a) = HType a
5959 type Unreify (AColumn context a) = Column context a
6060
61− fromColumns (HIdentity (Reify a)) = sfromColumn contextSing a
62− toColumns = HIdentity . Reify . stoColumn contextSing
61+ fromColumns (HType (Reify a)) = sfromColumn contextSing a
62+ toColumns = HType . Reify . stoColumn contextSing
6363 reify _ = AColumn
6464 unreify _ (AColumn a) = a
6565
@@ -77,7 +77,7 @@ instance
7777
7878sfromColumn :: ()
7979 => SContext context
80− -> Col context ('Spec labels a)
80+ -> Col context ('Spec a)
8181 -> AColumn context a
8282sfromColumn = \case
8383 SAggregate -> \(A a) -> AColumn a
@@ -90,7 +90,7 @@ sfromColumn = \case
9090stoColumn :: ()
9191 => SContext context
9292 -> AColumn context a
93− -> Col context ('Spec labels a)
93+ -> Col context ('Spec a)
9494stoColumn = \case
9595 SAggregate -> \(AColumn a) -> A a
9696 SExpr -> \(AColumn a) -> E a
src/Rel8/Expr.hs+1−7
@@ -39,7 +39,6 @@ import Rel8.Expr.Opaleye
3939 )
4040import Rel8.Expr.Serialize ( litExpr )
4141import Rel8.Schema.Context ( Interpretation, Col )
42−import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
4342import Rel8.Schema.HTable.Identity ( HIdentity( HType ), HType )
4443import Rel8.Schema.Null ( Nullity( Null, NotNull ), Sql, nullable )
4544import Rel8.Schema.Reify ( notReify )
@@ -128,7 +127,7 @@ instance Sql DBFloating a => Floating (Expr a) where
128127
129128instance Interpretation Expr where
130129 data Col Expr _spec where
131− E :: {unE :: !(Expr a)} -> Col Expr ('Spec labels a)
130+ E :: {unE :: !(Expr a)} -> Col Expr ('Spec a)
132131
133132
134133instance Sql DBType a => Table Expr (Expr a) where
@@ -148,8 +147,3 @@ instance Sql DBType a => Recontextualize Expr Result (Expr a) (Identity a)
148147
149148
150149instance Sql DBType a => Recontextualize Result Expr (Identity a) (Expr a)
151−
152−
153−instance Labelable Expr where
154− labeler (E a) = E a
155− unlabeler (E a) = E a
src/Rel8/Generic/Construction/ADT.hs+23−31
@@ -48,7 +48,6 @@ import Rel8.Generic.Construction.Record
4848 )
4949import Rel8.Generic.Table.ADT ( GColumnsADT, GColumnsADT' )
5050import Rel8.Generic.Table.Record ( GColumns )
51−import Rel8.Schema.Context.Label ( HLabelable, hlabeler, hunlabeler )
5251import Rel8.Schema.HTable ( HTable )
5352import Rel8.Schema.HTable.Identity ( HType )
5453import Rel8.Schema.HTable.Label ( HLabel, hlabel, hunlabel )
@@ -64,23 +63,23 @@ import Data.Text ( pack )
6463
6564
6665type Null :: K.HContext -> Type
67−type Null context = forall labels a. ()
68− => SSpec ('Spec labels a)
69− -> context ('Spec labels (Nullify a))
66+type Null context = forall a. ()
67+ => SSpec ('Spec a)
68+ -> context ('Spec (Nullify a))
7069
7170
7271type Nullifier :: K.HContext -> Type
73−type Nullifier context = forall labels a. ()
74− => SSpec ('Spec labels a)
75− -> context ('Spec labels a)
76− -> context ('Spec labels (Nullify a))
72+type Nullifier context = forall a. ()
73+ => SSpec ('Spec a)
74+ -> context ('Spec a)
75+ -> context ('Spec (Nullify a))
7776
7877
7978type Unnullifier :: K.HContext -> Type
80−type Unnullifier context = forall labels a. ()
81− => SSpec ('Spec labels a)
82− -> context ('Spec labels (Nullify a))
83− -> context ('Spec labels a)
79+type Unnullifier context = forall a. ()
80+ => SSpec ('Spec a)
81+ -> context ('Spec (Nullify a))
82+ -> context ('Spec a)
8483
8584
8685type NoConstructor :: Symbol -> Symbol -> ErrorMessage
@@ -222,24 +221,23 @@ class GConstructableADT _Table _Columns f context rep where
222221instance
223222 ( htable ~ HLabel "tag" (HType Tag)
224223 , GConstructableADT' _Table _Columns f context htable rep
225− , HLabelable context
226224 )
227225 => GConstructableADT _Table _Columns f context (M1 D meta rep)
228226 where
229227 gbuildADT toColumns nullifier =
230228 gbuildADT' @_Table @_Columns @f @context @htable @rep toColumns nullifier .
231− hlabel hlabeler
229+ hlabel
232230
233231 gunbuildADT fromColumns unnullifier =
234− first (hunlabel hunlabeler) .
232+ first hunlabel .
235233 gunbuildADT' @_Table @_Columns @f @context @htable @rep fromColumns unnullifier
236234
237235 gconstructADT toColumns null nullifier mk =
238236 gconstructADT' @_Table @_Columns @f @context @htable @rep toColumns null nullifier
239− (hlabel hlabeler . mk)
237+ (hlabel . mk)
240238
241239 gdeconstructADT fromColumns unnullifier cases =
242− first (hunlabel hunlabeler) .
240+ first hunlabel .
243241 gdeconstructADT' @_Table @_Columns @f @context @htable @rep fromColumns unnullifier cases
244242
245243
@@ -334,7 +332,6 @@ instance {-# OVERLAPPABLE #-}
334332 ( HTable (GColumns _Columns rep)
335333 , KnownSymbol label
336334 , meta ~ 'MetaCons label _fixity _isRecord
337− , HLabelable context
338335 , GConstructable _Table _Columns f context rep
339336 , GColumnsADT' _Columns htable (M1 C meta rep) ~
340337 HProduct htable (HLabel label (HNullify (GColumns _Columns rep)))
@@ -343,7 +340,7 @@ instance {-# OVERLAPPABLE #-}
343340 where
344341 gbuildADT' toColumns nullifier htable =
345342 HProduct htable .
346− hlabel hlabeler .
343+ hlabel .
347344 hnullify (nullifier tag) .
348345 gconstruct @_Table @_Columns @f @context @rep toColumns
349346 where
@@ -354,13 +351,13 @@ instance {-# OVERLAPPABLE #-}
354351 , gdeconstruct @_Table @_Columns @f @context @rep fromColumns $
355352 runIdentity $
356353 hunnullify (\spec -> pure . unnullifier spec) $
357− hunlabel hunlabeler
354+ hunlabel
358355 a
359356 )
360357
361358 gconstructADT' toColumns _ nullifier mk =
362359 HProduct htable .
363− hlabel hlabeler .
360+ hlabel .
364361 hnullify nullifier .
365362 gconstruct @_Table @_Columns @f @context @rep toColumns
366363 where
@@ -375,11 +372,11 @@ instance {-# OVERLAPPABLE #-}
375372 a = gdeconstruct @_Table @_Columns @f @context @rep fromColumns $
376373 runIdentity $
377374 hunnullify (\spec -> pure . unnullifier spec) $
378− hunlabel hunlabeler
375+ hunlabel
379376 columns
380377 tag = Tag $ pack $ symbolVal (Proxy @label)
381378
382− gfill null htable = HProduct htable (hlabel hlabeler (hnulls null))
379+ gfill null htable = HProduct htable (hlabel (hnulls null))
383380
384381
385382type GMakeableADT
@@ -403,7 +400,6 @@ instance
403400 , fallback ~ TypeError (NoConstructor datatype name)
404401 , fields ~ GFields f (GConstructorADT' name rep fallback)
405402 , GMakeableADT' _Table _Columns f context htable name rep fields
406− , HLabelable context
407403 , KnownSymbol name
408404 )
409405 => GMakeableADT _Table _Columns f context name (M1 D meta rep)
@@ -414,7 +410,7 @@ instance
414410 toColumns null nullifier htable
415411 where
416412 tag = Tag $ pack $ symbolVal (Proxy @name)
417− htable = hlabel hlabeler (wrap tag)
413+ htable = hlabel (wrap tag)
418414
419415
420416type GMakeableADT'
@@ -462,8 +458,6 @@ instance {-# OVERLAPS #-}
462458
463459instance {-# OVERLAPS #-}
464460 ( HTable (GColumns _Columns rep)
465− , KnownSymbol name
466− , HLabelable context
467461 , GConstructable _Table _Columns f context rep
468462 , fields ~ GFields f rep
469463 , GColumnsADT' _Columns htable (M1 C ('MetaCons name _fixity _isRecord) rep) ~
@@ -473,15 +467,13 @@ instance {-# OVERLAPS #-}
473467 where
474468 gmakeADT' toColumns _ nullifier htable =
475469 HProduct htable .
476− hlabel hlabeler .
470+ hlabel .
477471 hnullify nullifier .
478472 gconstruct @_Table @_Columns @f @context @rep toColumns
479473
480474
481475instance {-# OVERLAPPABLE #-}
482476 ( HTable (GColumns _Columns rep)
483− , KnownSymbol label
484− , HLabelable context
485477 , GColumnsADT' _Columns htable (M1 C ('MetaCons label _fixity _isRecord) rep) ~
486478 HProduct htable (HLabel label (HNullify (GColumns _Columns rep)))
487479 )
@@ -489,5 +481,5 @@ instance {-# OVERLAPPABLE #-}
489481 where
490482 gmakeADT' _ null _ htable _ =
491483 HProduct htable $
492− hlabel hlabeler $
484+ hlabel $
493485 hnulls null
src/Rel8/Generic/Construction/Record.hs+3−8
@@ -27,15 +27,13 @@ import GHC.Generics
2727 )
2828import GHC.TypeLits
2929 ( ErrorMessage( (:<>:), Text ), TypeError
30− , Symbol, KnownSymbol
30+ , Symbol
3131 )
3232import Prelude
3333
3434-- rel8
3535import Rel8.FCF ( Eval, Exp )
3636import Rel8.Generic.Table.Record ( GColumns )
37−import Rel8.Schema.Context.Label ( HLabelable, hlabeler, hunlabeler )
38−import Rel8.Schema.HTable ( HTable )
3937import Rel8.Schema.HTable.Label ( hlabel, hunlabel )
4038import Rel8.Schema.HTable.Product ( HProduct( HProduct ) )
4139import qualified Rel8.Schema.Kind as K
@@ -162,12 +160,9 @@ instance
162160
163161instance
164162 ( Eval (_Table a)
165− , HTable (Eval (_Columns a))
166− , HLabelable context
167− , KnownSymbol label
168163 , meta ~ 'MetaSel ('Just label) _su _ss _ds
169164 )
170165 => GConstructable _Table _Columns f context (M1 S meta (K1 i a))
171166 where
172− gconstruct toColumns = hlabel hlabeler . toColumns (Proxy @a)
173− gdeconstruct fromColumns = fromColumns (Proxy @a) . hunlabel hunlabeler
167+ gconstruct toColumns = hlabel . toColumns (Proxy @a)
168+ gdeconstruct fromColumns = fromColumns (Proxy @a) . hunlabel
src/Rel8/Generic/Rel8able.hs+4−5
@@ -36,7 +36,6 @@ import Rel8.Generic.Table ( GAlgebra )
3636import qualified Rel8.Generic.Table.Record as G
3737import qualified Rel8.Kind.Algebra as K ( Algebra(..) )
3838import Rel8.Schema.Context ( Col )
39−import Rel8.Schema.Context.Label ( Labelable )
4039import Rel8.Schema.HTable ( HTable )
4140import qualified Rel8.Schema.Kind as K
4241import Rel8.Schema.Reify ( Reify, UnwrapReify )
@@ -98,16 +97,16 @@ type Rel8able :: K.Rel8able -> Constraint
9897class HTable (GColumns t) => Rel8able t where
9998 type GColumns t :: K.HTable
10099
101− gfromColumns :: (Labelable context, Reifiable context)
100+ gfromColumns :: Reifiable context
102101 => GColumns t (Col (Reify context)) -> t (Reify context)
103102
104− gtoColumns :: (Labelable context, Reifiable context)
103+ gtoColumns :: Reifiable context
105104 => t (Reify context) -> GColumns t (Col (Reify context))
106105
107− greify :: (Labelable context, Reifiable context)
106+ greify :: Reifiable context
108107 => t context -> t (Reify context)
109108
110− gunreify :: (Labelable context, Reifiable context)
109+ gunreify :: Reifiable context
111110 => t (Reify context) -> t context
112111
113112 type GColumns t = G.GColumns TColumns (GRep t (Reify Result))
src/Rel8/Generic/Table.hs+4−4
@@ -148,10 +148,10 @@ ggtable :: forall algebra _Table _Columns rep context.
148148 , Eval (GGTable algebra _Table _Columns context rep)
149149 )
150150 => (forall a proxy. Eval (_Table a) => proxy a -> Eval (_Columns a) context)
151− -> (forall a labels. ()
152− => SSpec ('Spec labels a)
153− -> context ('Spec labels a)
154− -> context ('Spec labels (Nullify a)))
151+ -> (forall a. ()
152+ => SSpec ('Spec a)
153+ -> context ('Spec a)
154+ -> context ('Spec (Nullify a)))
155155 -> Eval (GGColumns algebra _Columns rep) context
156156ggtable = case algebraSing @algebra of
157157 SProduct -> \table _ -> gtable @_Table @_Columns @_ @rep table
src/Rel8/Generic/Table/ADT.hs+14−17
@@ -37,7 +37,6 @@ import Rel8.Generic.Table.Record
3737 ( GTable, GColumns, gtable
3838 , GToExprs, gfromResult, gtoResult
3939 )
40−import Rel8.Schema.Context.Label ( HLabelable, hlabeler, labeler, unlabeler )
4140import Rel8.Schema.HTable ( HTable, hmap )
4241import Rel8.Schema.HTable.Identity ( HIdentity( HType ), HType )
4342import Rel8.Schema.HTable.Label ( HLabel, hlabel, hunlabel )
@@ -96,10 +95,10 @@ class GTableADT _Table _Columns context rep where
9695
9796 gtableADT :: ()
9897 => (forall a proxy. Eval (_Table a) => proxy a -> Eval (_Columns a) context)
99− -> (forall a labels. ()
100− => SSpec ('Spec labels a)
101− -> context ('Spec labels a)
102− -> context ('Spec labels (Nullify a)))
98+ -> (forall a. ()
99+ => SSpec ('Spec a)
100+ -> context ('Spec a)
101+ -> context ('Spec (Nullify a)))
103102 -> GColumnsADT _Columns rep context
104103
105104
@@ -136,10 +135,10 @@ type GTableADT'
136135class GTableADT' _Table _Columns htable context rep where
137136 gtableADT' :: ()
138137 => (forall a proxy. Eval (_Table a) => proxy a -> Eval (_Columns a) context)
139− -> (forall a labels. ()
140− => SSpec ('Spec labels a)
141− -> context ('Spec labels a)
142− -> context ('Spec labels (Nullify a)))
138+ -> (forall a. ()
139+ => SSpec ('Spec a)
140+ -> context ('Spec a)
141+ -> context ('Spec (Nullify a)))
143142 -> htable context
144143 -> GColumnsADT' _Columns htable rep context
145144
@@ -165,9 +164,7 @@ instance meta ~ 'MetaCons label _fixity _isRecord =>
165164instance {-# OVERLAPPABLE #-}
166165 ( HTable (GColumns _Columns rep)
167166 , GTable _Table _Columns context rep
168− , HLabelable context
169167 , meta ~ 'MetaCons label _fixity _isRecord
170− , KnownSymbol label
171168 , GColumnsADT' _Columns htable (M1 C ('MetaCons label _fixity _isRecord) rep) ~
172169 HProduct htable (HLabel label (HNullify (GColumns _Columns rep)))
173170 )
@@ -175,7 +172,7 @@ instance {-# OVERLAPPABLE #-}
175172 where
176173 gtableADT' table hnullifier htable =
177174 HProduct htable $
178− hlabel hlabeler $
175+ hlabel $
179176 hnullify hnullifier $
180177 gtable @_Table @_Columns @_ @rep table
181178
@@ -219,12 +216,12 @@ instance
219216 Just rep -> M1 rep
220217 _ -> error "ADT.fromColumns: mismatch between tag and data"
221218 where
222− tag = (\(HType (R a)) -> a) . hunlabel @_ @"tag" unlabeler
219+ tag = (\(HType (R a)) -> a) . hunlabel @"tag"
223220
224221 gtoResultADT toResult (M1 rep) =
225222 gtoResultADT' @_ToExprs @_Columns @_ @exprs toResult tag (Just rep)
226223 where
227− tag = hlabel @_ @"tag" labeler . HType . R
224+ tag = hlabel @"tag" . HType . R
228225
229226
230227type GToExprsADT'
@@ -342,15 +339,15 @@ instance {-# OVERLAPPABLE #-}
342339 gfromResultADT' fromResult tag (HProduct a b)
343340 | tag a == tag' =
344341 M1 . gfromResult @_ToExprs @_Columns @exprs fromResult <$>
345− hunnullify unnullifier (hunlabel unlabeler b)
342+ hunnullify unnullifier (hunlabel b)
346343 | otherwise = Nothing
347344 where
348345 tag' = Tag $ pack $ symbolVal (Proxy @label)
349346
350347 gtoResultADT' toResult tag = \case
351− Nothing -> HProduct (tag tag') (hlabel labeler (hnulls (const null)))
348+ Nothing -> HProduct (tag tag') (hlabel (hnulls (const null)))
352349 Just (M1 rep) -> HProduct (tag tag') $
353− hlabel labeler $
350+ hlabel $
354351 hnullify nullifier $
355352 gtoResult @_ToExprs @_Columns @exprs toResult rep
356353 where
src/Rel8/Generic/Table/Record.hs+6−12
@@ -26,13 +26,11 @@ import GHC.Generics
2626 , C, D, S
2727 , Meta( MetaSel )
2828 )
29−import GHC.TypeLits ( KnownSymbol )
3029import Prelude hiding ( null )
3130
3231-- rel8
3332import Rel8.FCF ( Eval, Exp )
3433import Rel8.Schema.Context ( Col )
35−import Rel8.Schema.Context.Label ( HLabelable, hlabeler, hunlabeler )
3634import Rel8.Schema.HTable ( HTable )
3735import Rel8.Schema.HTable.Label ( HLabel, hlabel, hunlabel )
3836import Rel8.Schema.HTable.Product ( HProduct(..) )
@@ -116,18 +114,15 @@ instance
116114
117115
118116instance
119− ( HTable (Eval (_Columns a))
120− , Eval (_Table a)
121− , HLabelable context
122− , KnownSymbol label
117+ ( Eval (_Table a)
123118 , meta ~ 'MetaSel ('Just label) _su _ss _ds
124119 , k1 ~ K1 i a
125120 )
126121 => GTable _Table _Columns context (M1 S meta k1)
127122 where
128− gfromColumns fromColumns = M1 . K1 . fromColumns . hunlabel hunlabeler
129− gtoColumns toColumns (M1 (K1 a)) = hlabel hlabeler (toColumns a)
130− gtable table = hlabel hlabeler (table (Proxy @a))
123+ gfromColumns fromColumns = M1 . K1 . fromColumns . hunlabel
124+ gtoColumns toColumns (M1 (K1 a)) = hlabel (toColumns a)
125+ gtable table = hlabel (table (Proxy @a))
131126
132127
133128type GToExprs
@@ -193,7 +188,6 @@ instance
193188instance
194189 ( Eval (_ToExprs exprs a)
195190 , HTable (Eval (_Columns exprs))
196− , KnownSymbol label
197191 , meta ~ 'MetaSel ('Just label) _su _ss _ds
198192 , k1 ~ K1 i exprs
199193 , k1' ~ K1 i a
@@ -201,6 +195,6 @@ instance
201195 => GToExprs _ToExprs _Columns (M1 S meta k1) (M1 S meta k1')
202196 where
203197 gfromResult fromResult =
204− M1 . K1 . fromResult (Proxy @exprs) . hunlabel hunlabeler
198+ M1 . K1 . fromResult (Proxy @exprs) . hunlabel
205199 gtoResult toResult (M1 (K1 a)) =
206− hlabel hlabeler (toResult (Proxy @exprs) a)
200+ hlabel (toResult (Proxy @exprs) a)
src/Rel8/Kind/Context.hs−12
@@ -7,7 +7,6 @@ module Rel8.Kind.Context
77 ( Reifiable( contextSing )
88 , SContext(..)
99 , sReifiable
10− , sLabelable
1110 )
1211where
1312
@@ -20,7 +19,6 @@ import Rel8.Aggregate ( Aggregate )
2019import Rel8.Expr ( Expr )
2120import Rel8.Schema.Dict ( Dict( Dict ) )
2221import Rel8.Schema.Context ( Interpretation )
23−import Rel8.Schema.Context.Label ( Labelable )
2422import Rel8.Schema.Kind ( Context )
2523import Rel8.Schema.Name ( Name )
2624import Rel8.Schema.Reify ( Reify )
@@ -69,13 +67,3 @@ sReifiable = \case
6967 SResult -> Dict
7068 SReify context -> case sReifiable context of
7169 Dict -> Dict
72−
73−
74−sLabelable :: SContext context -> Dict Labelable context
75−sLabelable = \case
76− SAggregate -> Dict
77− SExpr -> Dict
78− SName -> Dict
79− SResult -> Dict
80− SReify context -> case sLabelable context of
81− Dict -> Dict
src/Rel8/Kind/Labels.hsdeleted−57
@@ -1,57 +0,0 @@
1−{-# language DataKinds #-}
2−{-# language FlexibleContexts #-}
3−{-# language FlexibleInstances #-}
4−{-# language GADTs #-}
5−{-# language LambdaCase #-}
6−{-# language StandaloneKindSignatures #-}
7−{-# language TypeOperators #-}
8−
9−module Rel8.Kind.Labels
10− ( Labels
11− , SLabels( SNil, SCons )
12− , KnownLabels( labelsSing )
13− , renderLabels
14− )
15−where
16−
17−-- base
18−import Data.Kind ( Constraint, Type )
19−import Data.List.NonEmpty ( NonEmpty, nonEmpty )
20−import Data.Maybe ( fromMaybe )
21−import Data.Proxy ( Proxy( Proxy ) )
22−import GHC.TypeLits ( KnownSymbol, Symbol, symbolVal )
23−import Prelude
24−
25−
26−type Labels :: Type
27−type Labels = [Symbol]
28−
29−
30−type SLabels :: Labels -> Type
31−data SLabels labels where
32− SNil :: SLabels '[]
33− SCons :: KnownSymbol label => Proxy label -> SLabels labels -> SLabels (label ': labels)
34−
35−
36−type KnownLabels :: Labels -> Constraint
37−class KnownLabels labels where
38− labelsSing :: SLabels labels
39−
40−
41−instance KnownLabels '[] where
42− labelsSing = SNil
43−
44−
45−instance (KnownSymbol label, KnownLabels labels) =>
46− KnownLabels (label ': labels)
47− where
48− labelsSing = SCons Proxy labelsSing
49−
50−
51−renderLabels :: SLabels labels -> NonEmpty String
52−renderLabels = fromMaybe (pure "anon") . nonEmpty . go
53− where
54− go :: SLabels labels -> [String]
55− go = \case
56− SNil -> []
57− SCons label labels -> symbolVal label : go labels
src/Rel8/Schema/Context/Label.hsdeleted−62
@@ -1,62 +0,0 @@
1−{-# language DataKinds #-}
2−{-# language FlexibleInstances #-}
3−{-# language StandaloneKindSignatures #-}
4−{-# language TypeFamilies #-}
5−{-# language TypeOperators #-}
6−
7−module Rel8.Schema.Context.Label
8− ( Labelable( labeler, unlabeler )
9− , HLabelable( hlabeler, hunlabeler )
10− )
11−where
12−
13−-- base
14−import Data.Kind ( Constraint )
15−import Prelude hiding ( null )
16−
17−-- rel8
18−import Rel8.Schema.Context ( Interpretation )
19−import Rel8.Schema.Dict ( Dict( Dict ) )
20−import Rel8.Schema.Kind ( Context, HContext )
21−import Rel8.Schema.Spec ( Spec( Spec ) )
22−import Rel8.Schema.Result ( Col( R ), Result )
23−import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
24−
25−
26−-- | The @Labelable@ class is an internal implementation detail of Rel8, and
27−-- indicates that we can successfully "name" all columns in a type.
28−type Labelable :: Context -> Constraint
29−class Interpretation context => Labelable context where
30− labeler :: ()
31− => Col context ('Spec labels a)
32− -> Col context ('Spec (label ': labels) a)
33−
34− unlabeler :: ()
35− => Col context ('Spec (label ': labels) a)
36− -> Col context ('Spec labels a)
37−
38−
39−instance Labelable Result where
40− labeler (R a) = R a
41− unlabeler (R a) = R a
42−
43−
44−type HLabelable :: HContext -> Constraint
45−class HLabelable context where
46− hlabeler :: ()
47− => context ('Spec labels a)
48− -> context ('Spec (label ': labels) a)
49−
50− hunlabeler :: ()
51− => context ('Spec (label ': labels) a)
52− -> context ('Spec labels a)
53−
54−
55−instance Labelable context => HLabelable (Col context) where
56− hlabeler = labeler
57− hunlabeler = unlabeler
58−
59−
60−instance HLabelable (Dict (ConstrainDBType constraint)) where
61− hlabeler Dict = Dict
62− hunlabeler Dict = Dict
src/Rel8/Schema/Context/Nullify.hs+16−17
@@ -51,31 +51,30 @@ class Interpretation context => Nullifiable context where
5151
5252 encodeTag ::
5353 ( Sql (ConstrainTag context) a
54− , KnownSymbol label
5554 , Taggable a
5655 )
5756 => Tag label a
58− -> Col context ('Spec labels a)
57+ -> Col context ('Spec a)
5958
6059 decodeTag ::
6160 ( Sql (ConstrainTag context) a
6261 , KnownSymbol label
6362 , Taggable a
6463 )
65− => Col context ('Spec labels a)
64+ => Col context ('Spec a)
6665 -> Tag label a
6766
6867 nullifier :: ()
6968 => Tag label a
7069 -> (Expr a -> Expr Bool)
71− -> SSpec ('Spec labels x)
72− -> Col context ('Spec labels x)
73− -> Col context ('Spec labels (Nullify x))
70+ -> SSpec ('Spec x)
71+ -> Col context ('Spec x)
72+ -> Col context ('Spec (Nullify x))
7473
7574 unnullifier :: ()
76− => SSpec ('Spec labels x)
77− -> Col context ('Spec labels (Nullify x))
78− -> Col context ('Spec labels x)
75+ => SSpec ('Spec x)
76+ -> Col context ('Spec (Nullify x))
77+ -> Col context ('Spec x)
7978
8079
8180instance Nullifiable Aggregate where
@@ -147,23 +146,23 @@ class HNullifiable context where
147146
148147 hencodeTag :: (Sql (HConstrainTag context) a, KnownSymbol label, Taggable a)
149148 => Tag label a
150− -> context ('Spec labels a)
149+ -> context ('Spec a)
151150
152151 hdecodeTag :: (Sql (HConstrainTag context) a, KnownSymbol label, Taggable a)
153− => context ('Spec labels a)
152+ => context ('Spec a)
154153 -> Tag label a
155154
156155 hnullifier :: ()
157156 => Tag label a
158157 -> (Expr a -> Expr Bool)
159− -> SSpec ('Spec labels x)
160− -> context ('Spec labels x)
161− -> context ('Spec labels (Nullify x))
158+ -> SSpec ('Spec x)
159+ -> context ('Spec x)
160+ -> context ('Spec (Nullify x))
162161
163162 hunnullifier :: ()
164− => SSpec ('Spec labels x)
165− -> context ('Spec labels (Nullify x))
166− -> context ('Spec labels x)
163+ => SSpec ('Spec x)
164+ -> context ('Spec (Nullify x))
165+ -> context ('Spec x)
167166
168167
169168instance Nullifiable context => HNullifiable (Col context) where
src/Rel8/Schema/HTable/Either.hs+2−3
@@ -15,17 +15,16 @@ import Prelude ()
1515
1616-- rel8
1717import Rel8.Schema.HTable ( HTable )
18−import Rel8.Schema.HTable.Identity ( HIdentity(..) )
18+import Rel8.Schema.HTable.Identity ( HType )
1919import Rel8.Schema.HTable.Label ( HLabel )
2020import Rel8.Schema.HTable.Nullify ( HNullify )
2121import qualified Rel8.Schema.Kind as K
22−import Rel8.Schema.Spec ( Spec( Spec ) )
2322import Rel8.Type.Tag ( EitherTag )
2423
2524
2625type HEitherTable :: K.HTable -> K.HTable -> K.HTable
2726data HEitherTable left right context = HEitherTable
28− { htag :: HIdentity ('Spec '["isRight"] EitherTag) context
27+ { htag :: HLabel "isRight" (HType EitherTag) context
2928 , hleft :: HLabel "Left" (HNullify left) context
3029 , hright :: HLabel "Right" (HNullify right) context
3130 }
src/Rel8/Schema/HTable/Identity.hs+2−2
@@ -25,10 +25,10 @@ import Rel8.Schema.Spec ( Spec( Spec ), KnownSpec, specSing )
2525
2626
2727type HType :: Type -> K.HTable
28−type HType a = HIdentity ('Spec '[] a)
28+type HType a = HIdentity ('Spec a)
2929
3030
31−pattern HType :: context ('Spec '[] a) -> HType a context
31+pattern HType :: context ('Spec a) -> HType a context
3232pattern HType a = HIdentity a
3333{-# COMPLETE HType #-}
3434
src/Rel8/Schema/HTable/Label.hs+27−52
@@ -1,83 +1,58 @@
1−{-# LANGUAGE DeriveAnyClass #-}
2−{-# LANGUAGE DeriveGeneric #-}
3−{-# LANGUAGE DerivingStrategies #-}
4−{-# LANGUAGE LambdaCase #-}
5−{-# language ConstraintKinds #-}
61{-# language DataKinds #-}
7−{-# language FlexibleInstances #-}
8−{-# language GADTs #-}
9−{-# language MultiParamTypeClasses #-}
10−{-# language QuantifiedConstraints #-}
11−{-# language RankNTypes #-}
122{-# language RecordWildCards #-}
133{-# language ScopedTypeVariables #-}
144{-# language StandaloneKindSignatures #-}
5+{-# language TypeApplications #-}
156{-# language TypeFamilies #-}
16−{-# language TypeOperators #-}
17−{-# language UndecidableInstances #-}
187
198module Rel8.Schema.HTable.Label
20− ( HLabel, Label
21− , hlabel, hunlabel
9+ ( HLabel, hlabel, hrelabel, hunlabel
2210 )
2311where
2412
2513-- base
14+import Data.Kind ( Type )
2615import Data.Proxy ( Proxy( Proxy ) )
27−import GHC.TypeLits ( KnownSymbol, Symbol )
16+import GHC.TypeLits ( KnownSymbol, Symbol, symbolVal )
2817import Prelude
2918
3019-- rel8
31−import Rel8.Kind.Labels ( SLabels( SCons ) )
3220import Rel8.Schema.HTable
33− ( HTable
34− , hfield, htabulate, hspecs
35− )
3621import qualified Rel8.Schema.Kind as K
37−import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
38−import Rel8.FCF
39−import Rel8.Schema.HTable.MapTable
40−import GHC.Generics (Generic)
22+import Rel8.Schema.Spec ( Spec, SSpec(..) )
4123
4224
4325type HLabel :: Symbol -> K.HTable -> K.HTable
44−newtype HLabel label table context = HLabel (HMapTable (Label label) table context)
45− deriving stock Generic
46− deriving anyclass HTable
47−
26+newtype HLabel label table context = HLabel (table context)
4827
49−data Label :: Symbol -> Spec -> Exp Spec
5028
29+type HLabelField :: Symbol -> K.HTable -> Spec -> Type
30+newtype HLabelField label table spec = HLabelField (HField table spec)
5131
52−type instance Eval (Label label ('Spec labels a)) = 'Spec (label : labels) a
5332
33+instance (HTable table, KnownSymbol label) => HTable (HLabel label table) where
34+ type HField (HLabel label table) = HLabelField label table
35+ type HConstrainTable (HLabel label table) constraint =
36+ HConstrainTable table constraint
5437
55−instance KnownSymbol l => MapSpec (Label l) where
56− mapInfo = \case
57− SSpec {..} -> SSpec {labels = SCons Proxy labels, ..}
38+ hfield (HLabel a) (HLabelField field) = hfield a field
39+ htabulate f = HLabel (htabulate (f . HLabelField))
40+ htraverse f (HLabel a) = HLabel <$> htraverse f a
41+ hdicts = HLabel (hdicts @table)
42+ hspecs = HLabel $ htabulate $ \field -> case hfield (hspecs @table) field of
43+ SSpec {..} -> SSpec {labels = symbolVal (Proxy @label) : labels, ..}
5844
5945
60−hlabel :: (HTable t, KnownSymbol label)
61− => (forall labels a. ()
62− => context ('Spec labels a)
63− -> context ('Spec (label ': labels) a))
64− -> t context
65− -> HLabel label t context
66−hlabel labeler a = HLabel $ htabulate $ \(HMapTableField field) ->
67− case hfield hspecs field of
68− SSpec {} -> labeler (hfield a field)
46+hlabel :: forall label t context. t context -> HLabel label t context
47+hlabel = HLabel
6948{-# INLINABLE hlabel #-}
7049
7150
72−hunlabel :: (HTable t, KnownSymbol label)
73− => (forall labels a. ()
74− => context ('Spec (label ': labels) a)
75− -> context ('Spec labels a))
76− -> HLabel label t context
77− -> t context
78−hunlabel unlabler (HLabel as) =
79− htabulate $ \field ->
80− case hfield hspecs field of
81− SSpec {} -> case hfield as (HMapTableField field) of
82− a -> unlabler a
51+hrelabel :: forall label' label t context. HLabel label t context -> HLabel label' t context
52+hrelabel = hlabel . hunlabel
53+{-# INLINABLE hrelabel #-}
54+
55+
56+hunlabel :: forall label t context. HLabel label t context -> t context
57+hunlabel (HLabel a) = a
8358{-# INLINABLE hunlabel #-}
src/Rel8/Schema/HTable/Maybe.hs+2−3
@@ -15,17 +15,16 @@ import Prelude
1515
1616-- rel8
1717import Rel8.Schema.HTable ( HTable )
18−import Rel8.Schema.HTable.Identity ( HIdentity(..) )
18+import Rel8.Schema.HTable.Identity ( HType )
1919import Rel8.Schema.HTable.Label ( HLabel )
2020import Rel8.Schema.HTable.Nullify ( HNullify )
2121import qualified Rel8.Schema.Kind as K
22−import Rel8.Schema.Spec ( Spec( Spec ) )
2322import Rel8.Type.Tag ( MaybeTag )
2423
2524
2625type HMaybeTable :: K.HTable -> K.HTable
2726data HMaybeTable table context = HMaybeTable
28− { htag :: HIdentity ('Spec '["isJust"] (Maybe MaybeTag)) context
27+ { htag :: HLabel "isJust" (HType (Maybe MaybeTag)) context
2928 , hjust :: HLabel "Just" (HNullify table) context
3029 }
3130 deriving stock Generic
src/Rel8/Schema/HTable/Nullify.hs+17−17
@@ -10,6 +10,7 @@
1010{-# language NamedFieldPuns #-}
1111{-# language QuantifiedConstraints #-}
1212{-# language RankNTypes #-}
13+{-# language RecordWildCards #-}
1314{-# language ScopedTypeVariables #-}
1415{-# language StandaloneKindSignatures #-}
1516{-# language TypeFamilies #-}
@@ -50,25 +51,24 @@ newtype HNullify table context = HNullify (HMapTable Nullify table context)
5051data Nullify :: Spec -> Exp Spec
5152
5253
53−type instance Eval (Nullify ('Spec labels a)) =
54− 'Spec labels (Type.Nullify a)
54+type instance Eval (Nullify ('Spec a)) =
55+ 'Spec (Type.Nullify a)
5556
5657
5758instance MapSpec Nullify where
5859 mapInfo = \case
59− SSpec{labels, info, nullity} -> SSpec
60− { labels
61− , info
62− , nullity = case nullity of
60+ SSpec {nullity, ..} -> SSpec
61+ { nullity = case nullity of
6362 Null -> Null
6463 NotNull -> Null
64+ , ..
6565 }
6666
6767
6868hnulls :: HTable t
69− => (forall labels a. ()
70− => SSpec ('Spec labels a)
71− -> context ('Spec labels (Type.Nullify a)))
69+ => (forall a. ()
70+ => SSpec ('Spec a)
71+ -> context ('Spec (Type.Nullify a)))
7272 -> HNullify t context
7373hnulls null = HNullify $ htabulate $ \(HMapTableField field) -> case hfield hspecs field of
7474 spec@SSpec {} -> null spec
@@ -76,10 +76,10 @@ hnulls null = HNullify $ htabulate $ \(HMapTableField field) -> case hfield hspe
7676
7777
7878hnullify :: HTable t
79− => (forall labels a. ()
80− => SSpec ('Spec labels a)
81− -> context ('Spec labels a)
82− -> context ('Spec labels (Type.Nullify a)))
79+ => (forall a. ()
80+ => SSpec ('Spec a)
81+ -> context ('Spec a)
82+ -> context ('Spec (Type.Nullify a)))
8383 -> t context
8484 -> HNullify t context
8585hnullify nullifier a = HNullify $ htabulate $ \(HMapTableField field) ->
@@ -89,10 +89,10 @@ hnullify nullifier a = HNullify $ htabulate $ \(HMapTableField field) ->
8989
9090
9191hunnullify :: (HTable t, Apply m)
92− => (forall labels a. ()
93− => SSpec ('Spec labels a)
94− -> context ('Spec labels (Type.Nullify a))
95− -> m (context ('Spec labels a)))
92+ => (forall a. ()
93+ => SSpec ('Spec a)
94+ -> context ('Spec (Type.Nullify a))
95+ -> m (context ('Spec a)))
9696 -> HNullify t context
9797 -> m (t context)
9898hunnullify unnullifier (HNullify as) =
src/Rel8/Schema/HTable/These.hs+3−4
@@ -15,19 +15,18 @@ import Prelude
1515
1616-- rel8
1717import Rel8.Schema.HTable ( HTable )
18−import Rel8.Schema.HTable.Identity ( HIdentity )
18+import Rel8.Schema.HTable.Identity ( HType )
1919import Rel8.Schema.HTable.Label ( HLabel )
2020import Rel8.Schema.HTable.Nullify ( HNullify )
2121import qualified Rel8.Schema.Kind as K
22−import Rel8.Schema.Spec ( Spec( Spec ) )
2322import Rel8.Type.Tag ( MaybeTag )
2423
2524
2625type HTheseTable :: K.HTable -> K.HTable -> K.HTable
2726data HTheseTable here there context = HTheseTable
28− { hhereTag :: HIdentity ('Spec '["hasHere"] (Maybe MaybeTag)) context
27+ { hhereTag :: HLabel "hereTag" (HType (Maybe MaybeTag)) context
2928 , hhere :: HLabel "Here" (HNullify here) context
30− , hthereTag :: HIdentity ('Spec '["hasThere"] (Maybe MaybeTag)) context
29+ , hthereTag :: HLabel "thereTag" (HType (Maybe MaybeTag)) context
3130 , hthere :: HLabel "There" (HNullify there) context
3231 }
3332 deriving stock Generic
src/Rel8/Schema/HTable/Vectorize.hs+15−21
@@ -32,7 +32,6 @@ import Data.List.NonEmpty ( NonEmpty )
3232import Prelude
3333
3434-- rel8
35−import Rel8.Schema.Context.Label ( HLabelable, hlabeler, hunlabeler )
3635import Rel8.Schema.Dict ( Dict( Dict ) )
3736import qualified Rel8.Schema.Kind as K
3837import Rel8.Schema.HTable
@@ -78,7 +77,7 @@ newtype HVectorize list table context = HVectorize (HMapTable (Vectorize list) t
7877data Vectorize :: (Type -> Type) -> Spec -> Exp Spec
7978
8079
81−type instance Eval (Vectorize list ('Spec labels a)) = 'Spec labels (list a)
80+type instance Eval (Vectorize list ('Spec a)) = 'Spec (list a)
8281
8382
8483instance Vector list => MapSpec (Vectorize list) where
@@ -92,10 +91,10 @@ instance Vector list => MapSpec (Vectorize list) where
9291
9392
9493hvectorize :: (HTable t, Unzip f, Vector list)
95− => (forall labels a. ()
96− => SSpec ('Spec labels a)
97− -> f (context ('Spec labels a))
98− -> context' ('Spec labels (list a)))
94+ => (forall a. ()
95+ => SSpec ('Spec a)
96+ -> f (context ('Spec a))
97+ -> context' ('Spec (list a)))
9998 -> f (t context)
10099 -> HVectorize list t context'
101100hvectorize vectorizer as = HVectorize $ htabulate $ \(HMapTableField field) ->
@@ -105,10 +104,10 @@ hvectorize vectorizer as = HVectorize $ htabulate $ \(HMapTableField field) ->
105104
106105
107106hunvectorize :: (HTable t, Zip f, Vector list)
108− => (forall labels a. ()
109− => SSpec ('Spec labels a)
110− -> context ('Spec labels (list a))
111− -> f (context' ('Spec labels a)))
107+ => (forall a. ()
108+ => SSpec ('Spec a)
109+ -> context ('Spec (list a))
110+ -> f (context' ('Spec a)))
112111 -> HVectorize list t context
113112 -> f (t context')
114113hunvectorize unvectorizer (HVectorize table) =
@@ -119,12 +118,12 @@ hunvectorize unvectorizer (HVectorize table) =
119118
120119
121120happend :: (HTable t, Vector list) =>
122− ( forall labels a. ()
121+ ( forall a. ()
123122 => Nullity a
124123 -> TypeInformation (Unnullify a)
125− -> context ('Spec labels (list a))
126− -> context ('Spec labels (list a))
127− -> context ('Spec labels (list a))
124+ -> context ('Spec (list a))
125+ -> context ('Spec (list a))
126+ -> context ('Spec (list a))
128127 )
129128 -> HVectorize list t context
130129 -> HVectorize list t context
@@ -136,16 +135,11 @@ happend append (HVectorize as) (HVectorize bs) = HVectorize $
136135
137136
138137hempty :: HTable t =>
139− ( forall labels a. ()
138+ ( forall a. ()
140139 => Nullity a
141140 -> TypeInformation (Unnullify a)
142− -> context ('Spec labels [a])
141+ -> context ('Spec [a])
143142 )
144143 -> HVectorize [] t context
145144hempty empty = HVectorize $ htabulate $ \(HMapTableField field) -> case hfield hspecs field of
146145 SSpec {nullity, info} -> empty nullity info
147−
148−
149−instance HLabelable g => HLabelable (Precompose (Vectorize list) g) where
150− hlabeler = Precompose . hlabeler . precomposed
151− hunlabeler = Precompose . hunlabeler . precomposed
src/Rel8/Schema/Name.hs+1−7
@@ -28,7 +28,6 @@ import Prelude
2828-- rel8
2929import Rel8.Expr ( Expr )
3030import Rel8.Schema.Context ( Interpretation, Col )
31−import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
3231import Rel8.Schema.HTable.Identity ( HIdentity( HType ), HType )
3332import Rel8.Schema.Null ( Sql )
3433import Rel8.Schema.Reify ( notReify )
@@ -84,12 +83,7 @@ instance Sql DBType a => Recontextualize Name Name (Name a) (Name a)
8483
8584instance Interpretation Name where
8685 data Col Name _spec where
87− N :: {unN :: !(Name a)} -> Col Name ('Spec labels a)
88−
89−
90−instance Labelable Name where
91− labeler (N a) = N a
92− unlabeler (N a) = N a
86+ N :: {unN :: !(Name a)} -> Col Name ('Spec a)
9387
9488
9589-- | @Selects a b@ means that @a@ is a schema (i.e., a 'Table' of 'Name's) for
src/Rel8/Schema/Reify.hs−6
@@ -23,7 +23,6 @@ import Prelude
2323
2424-- rel8
2525import Rel8.Schema.Context ( Interpretation, Col )
26−import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
2726import Rel8.Schema.HTable ( HTable, hmap )
2827import Rel8.Schema.Kind ( Context )
2928
@@ -36,11 +35,6 @@ instance Interpretation (Reify context) where
3635 newtype Col (Reify context) spec = Reify (Col context spec)
3736
3837
39−instance Labelable context => Labelable (Reify context) where
40− labeler (Reify a) = Reify (labeler a)
41− unlabeler (Reify a) = Reify (unlabeler a)
42−
43−
4438hreify :: HTable t => t (Col context) -> t (Col (Reify context))
4539hreify = hmap Reify
4640
src/Rel8/Schema/Result.hs+14−22
@@ -6,7 +6,6 @@
66
77module Rel8.Schema.Result
88 ( Col( R, unR ), Result
9− , relabel
109 , null, nullifier, unnullifier
1110 , vectorizer, unvectorizer
1211 )
@@ -17,7 +16,6 @@ import Prelude hiding ( null )
1716
1817-- rel8
1918import Rel8.Schema.Context ( Interpretation( Col ) )
20−import Rel8.Schema.HTable.Identity ( HIdentity(..) )
2119import Rel8.Schema.Kind ( Context )
2220import Rel8.Schema.Null ( Nullify, Nullity( Null, NotNull ) )
2321import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
@@ -33,32 +31,26 @@ data Result a
3331
3432instance Interpretation Result where
3533 data Col Result _spec where
36− R :: {unR :: !a} -> Col Result ('Spec labels a)
34+ R :: {unR :: !a} -> Col Result ('Spec a)
3735
3836
39−relabel :: ()
40− => HIdentity ('Spec labels a) (Col Result)
41− -> HIdentity ('Spec relabels a) (Col Result)
42−relabel (HIdentity (R a)) = HIdentity (R a)
43−
44−
45−null :: Col Result ('Spec labels (Maybe a))
37+null :: Col Result ('Spec (Maybe a))
4638null = R Nothing
4739
4840
4941nullifier :: ()
50− => SSpec ('Spec labels a)
51− -> Col Result ('Spec labels a)
52− -> Col Result ('Spec labels (Nullify a))
42+ => SSpec ('Spec a)
43+ -> Col Result ('Spec a)
44+ -> Col Result ('Spec (Nullify a))
5345nullifier SSpec {nullity} (R a) = R $ case nullity of
5446 Null -> a
5547 NotNull -> Just a
5648
5749
5850unnullifier :: ()
59− => SSpec ('Spec labels a)
60− -> Col Result ('Spec labels (Nullify a))
61− -> Maybe (Col Result ('Spec labels a))
51+ => SSpec ('Spec a)
52+ -> Col Result ('Spec (Nullify a))
53+ -> Maybe (Col Result ('Spec a))
6254unnullifier SSpec {nullity} (R a) =
6355 case nullity of
6456 Null -> pure $ R a
@@ -66,14 +58,14 @@ unnullifier SSpec {nullity} (R a) =
6658
6759
6860vectorizer :: Functor f
69− => SSpec ('Spec labels a)
70− -> f (Col Result ('Spec labels a))
71− -> Col Result ('Spec labels (f a))
61+ => SSpec ('Spec a)
62+ -> f (Col Result ('Spec a))
63+ -> Col Result ('Spec (f a))
7264vectorizer _ = R . fmap unR
7365
7466
7567unvectorizer :: Functor f
76− => SSpec ('Spec labels a)
77− -> Col Result ('Spec labels (f a))
78− -> f (Col Result ('Spec labels a))
68+ => SSpec ('Spec a)
69+ -> Col Result ('Spec (f a))
70+ -> f (Col Result ('Spec a))
7971unvectorizer _ (R results) = R <$> results
src/Rel8/Schema/Spec.hs+6−12
@@ -13,27 +13,26 @@ where
1313
1414-- base
1515import Data.Kind ( Constraint, Type )
16−import Prelude ()
16+import Prelude
1717
1818-- rel8
19−import Rel8.Kind.Labels ( Labels, SLabels, KnownLabels, labelsSing )
2019import Rel8.Schema.Null ( Nullity, Sql, Unnullify, nullable )
2120import Rel8.Type ( DBType, typeInformation )
2221import Rel8.Type.Information ( TypeInformation )
2322
2423
2524type Spec :: Type
26−data Spec = Spec Labels Type
25+newtype Spec = Spec Type
2726
2827
2928type SSpec :: Spec -> Type
3029data SSpec spec where
3130 SSpec ::
32− { labels :: SLabels labels
31+ { labels :: [String]
3332 , info :: TypeInformation (Unnullify a)
3433 , nullity :: Nullity a
3534 }
36− -> SSpec ('Spec labels a)
35+ -> SSpec ('Spec a)
3736
3837
3938type KnownSpec :: Spec -> Constraint
@@ -41,14 +40,9 @@ class KnownSpec spec where
4140 specSing :: SSpec spec
4241
4342
44−instance
45− ( KnownLabels labels
46− , Sql DBType a
47− )
48− => KnownSpec ('Spec labels a)
49− where
43+instance Sql DBType a => KnownSpec ('Spec a) where
5044 specSing = SSpec
51− { labels = labelsSing
45+ { labels = []
5246 , info = typeInformation
5347 , nullity = nullable
5448 }
src/Rel8/Schema/Spec/ConstrainDBType.hs+14−14
@@ -31,47 +31,47 @@ import Rel8.Schema.Spec ( Spec( Spec ), SSpec( SSpec, nullity ) )
3131
3232type ConstrainDBType :: (Type -> Constraint) -> Spec -> Constraint
3333class
34− ( forall c labels a. ()
35− => (spec ~ 'Spec labels a)
34+ ( forall c a. ()
35+ => (spec ~ 'Spec a)
3636 => (forall x. (constraint x => c x)) => Sql c a
3737 )
3838 => ConstrainDBType constraint spec
3939instance
40− ( spec ~ 'Spec labels a
40+ ( spec ~ 'Spec a
4141 , Sql constraint a
4242 )
4343 => ConstrainDBType constraint spec
4444
4545
46−dbTypeNullity :: Dict (ConstrainDBType c) ('Spec l a) -> Nullity a
46+dbTypeNullity :: Dict (ConstrainDBType c) ('Spec a) -> Nullity a
4747dbTypeNullity = step2 . step1
4848 where
49− step1 :: Dict (ConstrainDBType c) ('Spec l a) -> Dict (Sql c) a
49+ step1 :: Dict (ConstrainDBType c) ('Spec a) -> Dict (Sql c) a
5050 step1 Dict = Dict
5151
5252 step2 :: Dict (Sql c) a -> Nullity a
5353 step2 Dict = nullable
5454
5555
56−dbTypeDict :: Dict (ConstrainDBType c) ('Spec l a) -> Dict c (Unnullify a)
56+dbTypeDict :: Dict (ConstrainDBType c) ('Spec a) -> Dict c (Unnullify a)
5757dbTypeDict = step2 . step1
5858 where
59− step1 :: Dict (ConstrainDBType c) ('Spec l a) -> Dict (Sql c) a
59+ step1 :: Dict (ConstrainDBType c) ('Spec a) -> Dict (Sql c) a
6060 step1 Dict = Dict
6161
6262 step2 :: Dict (Sql c) a -> Dict c (Unnullify a)
6363 step2 Dict = Dict
6464
6565
66−fromNullityDict :: Nullity a -> Dict c (Unnullify a) -> Dict (ConstrainDBType c) ('Spec l a)
66+fromNullityDict :: Nullity a -> Dict c (Unnullify a) -> Dict (ConstrainDBType c) ('Spec a)
6767fromNullityDict Null Dict = Dict
6868fromNullityDict NotNull Dict = Dict
6969
7070
7171nullifier :: ()
72− => SSpec ('Spec labels a)
73− -> Dict (ConstrainDBType c) ('Spec labels a)
74− -> Dict (ConstrainDBType c) ('Spec labels (Nullify a))
72+ => SSpec ('Spec a)
73+ -> Dict (ConstrainDBType c) ('Spec a)
74+ -> Dict (ConstrainDBType c) ('Spec (Nullify a))
7575nullifier SSpec {} dict = case dbTypeDict dict of
7676 Dict -> case dbTypeNullity dict of
7777 Null -> Dict
@@ -79,9 +79,9 @@ nullifier SSpec {} dict = case dbTypeDict dict of
7979
8080
8181unnullifier :: ()
82− => SSpec ('Spec labels a)
83− -> Dict (ConstrainDBType c) ('Spec labels (Nullify a))
84− -> Dict (ConstrainDBType c) ('Spec labels a)
82+ => SSpec ('Spec a)
83+ -> Dict (ConstrainDBType c) ('Spec (Nullify a))
84+ -> Dict (ConstrainDBType c) ('Spec a)
8585unnullifier SSpec {nullity} dict = case dbTypeDict dict of
8686 Dict -> case nullity of
8787 Null -> Dict
src/Rel8/Table.hs+27−34
@@ -41,11 +41,10 @@ import Rel8.Generic.Table
4141 )
4242import Rel8.Generic.Record ( Record(..) )
4343import Rel8.Generic.Reify ( ARep )
44−import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
4544import Rel8.Schema.HTable ( HTable )
4645import Rel8.Schema.HTable.Either ( HEitherTable(..) )
4746import Rel8.Schema.HTable.Identity ( HIdentity(..), HType )
48−import Rel8.Schema.HTable.Label ( hlabel, hunlabel )
47+import Rel8.Schema.HTable.Label ( hlabel, hrelabel, hunlabel )
4948import Rel8.Schema.HTable.List ( HListTable )
5049import Rel8.Schema.HTable.Maybe ( HMaybeTable(..) )
5150import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
@@ -61,7 +60,6 @@ import Rel8.Schema.Reify
6160 )
6261import Rel8.Schema.Result
6362 ( Col( R ), Result
64− , relabel
6563 , null, nullifier, unnullifier
6664 , vectorizer, unvectorizer
6765 )
@@ -247,20 +245,20 @@ instance (Table Result a, Table Result b) => Table Result (Either a b) where
247245
248246 toColumns = \case
249247 Left table -> HEitherTable
250− { htag = HIdentity (R IsLeft)
251− , hleft = hlabel labeler (hnullify nullifier (toColumns table))
252− , hright = hlabel labeler (hnulls (const null))
248+ { htag = hlabel (HType (R IsLeft))
249+ , hleft = hlabel (hnullify nullifier (toColumns table))
250+ , hright = hlabel (hnulls (const null))
253251 }
254252 Right table -> HEitherTable
255− { htag = HIdentity (R IsRight)
256− , hleft = hlabel labeler (hnulls (const null))
257− , hright = hlabel labeler (hnullify nullifier (toColumns table))
253+ { htag = hlabel (HType (R IsRight))
254+ , hleft = hlabel (hnulls (const null))
255+ , hright = hlabel (hnullify nullifier (toColumns table))
258256 }
259257
260− fromColumns HEitherTable {htag, hleft, hright} = case htag of
261− HIdentity (R tag) -> case tag of
262− IsLeft -> maybe err (Left . fromColumns) $ hunnullify unnullifier (hunlabel unlabeler hleft)
263− IsRight -> maybe err (Right . fromColumns) $ hunnullify unnullifier (hunlabel unlabeler hright)
258+ fromColumns HEitherTable {htag, hleft, hright} = case hunlabel htag of
259+ HType (R tag) -> case tag of
260+ IsLeft -> maybe err (Left . fromColumns) $ hunnullify unnullifier (hunlabel hleft)
261+ IsRight -> maybe err (Right . fromColumns) $ hunnullify unnullifier (hunlabel hright)
264262 where
265263 err = error "Either.fromColumns: mismatch between tag and data"
266264
@@ -279,17 +277,17 @@ instance Table Result a => Table Result (Maybe a) where
279277
280278 toColumns = \case
281279 Nothing -> HMaybeTable
282− { htag = HIdentity (R Nothing)
283− , hjust = hlabel labeler (hnulls (const null))
280+ { htag = hlabel (HIdentity (R Nothing))
281+ , hjust = hlabel (hnulls (const null))
284282 }
285283 Just table -> HMaybeTable
286− { htag = HIdentity (R (Just IsJust))
287− , hjust = hlabel labeler (hnullify nullifier (toColumns table))
284+ { htag = hlabel (HIdentity (R (Just IsJust)))
285+ , hjust = hlabel (hnullify nullifier (toColumns table))
288286 }
289287
290− fromColumns HMaybeTable {htag, hjust} = case htag of
291− HIdentity (R tag) -> tag $>
292− case hunnullify unnullifier (hunlabel unlabeler hjust) of
288+ fromColumns HMaybeTable {htag, hjust} = case hunlabel htag of
289+ HType (R tag) -> tag $>
290+ case hunnullify unnullifier (hunlabel hjust) of
293291 Nothing -> error "Maybe.fromColumns: mismatch between tag and data"
294292 Just just -> fromColumns just
295293
@@ -307,10 +305,10 @@ instance (Table Result a, Table Result b) => Table Result (These a b) where
307305 type Context (These a b) = Result
308306
309307 toColumns tables = HTheseTable
310− { hhereTag = relabel hhereTag
311− , hhere = hlabel labeler (hunlabel unlabeler (toColumns hhere))
312− , hthereTag = relabel hthereTag
313− , hthere = hlabel labeler (hunlabel unlabeler (toColumns hthere))
308+ { hhereTag = hrelabel hhereTag
309+ , hhere = hrelabel (toColumns hhere)
310+ , hthereTag = hrelabel hthereTag
311+ , hthere = hrelabel (toColumns hthere)
314312 }
315313 where
316314 HMaybeTable
@@ -330,29 +328,27 @@ instance (Table Result a, Table Result b) => Table Result (These a b) where
330328 _ -> error "These.fromColumns: mismatch between tags and data"
331329 where
332330 mhere = HMaybeTable
333− { htag = relabel hhereTag
334− , hjust = hlabel labeler (hunlabel unlabeler hhere)
331+ { htag = hrelabel hhereTag
332+ , hjust = hrelabel hhere
335333 }
336334 mthere = HMaybeTable
337− { htag = relabel hthereTag
338− , hjust = hlabel labeler (hunlabel unlabeler hthere)
335+ { htag = hrelabel hthereTag
336+ , hjust = hrelabel hthere
339337 }
340338
341339
342−instance (Table context a, Table context b, Labelable context)
340+instance (Table context a, Table context b)
343341 => Table context (a, b)
344342
345343
346344instance
347345 ( Table context a, Table context b, Table context c
348− , Labelable context
349346 )
350347 => Table context (a, b, c)
351348
352349
353350instance
354351 ( Table context a, Table context b, Table context c, Table context d
355− , Labelable context
356352 )
357353 => Table context (a, b, c, d)
358354
@@ -360,7 +356,6 @@ instance
360356instance
361357 ( Table context a, Table context b, Table context c, Table context d
362358 , Table context e
363− , Labelable context
364359 )
365360 => Table context (a, b, c, d, e)
366361
@@ -368,7 +363,6 @@ instance
368363instance
369364 ( Table context a, Table context b, Table context c, Table context d
370365 , Table context e, Table context f
371− , Labelable context
372366 )
373367 => Table context (a, b, c, d, e, f)
374368
@@ -376,7 +370,6 @@ instance
376370instance
377371 ( Table context a, Table context b, Table context c, Table context d
378372 , Table context e, Table context f, Table context g
379− , Labelable context
380373 )
381374 => Table context (a, b, c, d, e, f, g)
382375
src/Rel8/Table/Either.hs+9−15
@@ -32,10 +32,6 @@ import Prelude hiding ( undefined )
3232-- rel8
3333import Rel8.Expr ( Expr )
3434import Rel8.Expr.Serialize ( litExpr )
35−import Rel8.Schema.Context.Label
36− ( Labelable
37− , HLabelable, hlabeler, hunlabeler
38− )
3935import Rel8.Schema.Context.Nullify
4036 ( Nullifiable, ConstrainTag
4137 , HNullifiable, HConstrainTag
@@ -111,7 +107,7 @@ instance (Table Expr a, Table Expr b) => Semigroup (EitherTable a b) where
111107
112108instance
113109 ( Table context a, Table context b
114− , Labelable context, Nullifiable context, ConstrainTag context EitherTag
110+ , Nullifiable context, ConstrainTag context EitherTag
115111 ) =>
116112 Table context (EitherTable a b)
117113 where
@@ -125,8 +121,8 @@ instance
125121
126122
127123instance
128− ( Nullifiable from, Labelable from, ConstrainTag from EitherTag
129− , Nullifiable to, Labelable to, ConstrainTag to EitherTag
124+ ( Nullifiable from, ConstrainTag from EitherTag
125+ , Nullifiable to, ConstrainTag to EitherTag
130126 , Recontextualize from to a1 b1
131127 , Recontextualize from to a2 b2
132128 )
@@ -206,7 +202,6 @@ toColumns2 ::
206202 ( HTable t
207203 , HTable u
208204 , HConstrainTag context EitherTag
209− , HLabelable context
210205 , HNullifiable context
211206 )
212207 => (a -> t context)
@@ -215,18 +210,17 @@ toColumns2 ::
215210 -> HEitherTable t u context
216211toColumns2 f g EitherTable {tag, left, right} = HEitherTable
217212 { htag
218− , hleft = hlabel hlabeler $ hnullify (hnullifier tag isLeft) $ f left
219− , hright = hlabel hlabeler $ hnullify (hnullifier tag isRight) $ g right
213+ , hleft = hlabel $ hnullify (hnullifier tag isLeft) $ f left
214+ , hright = hlabel $ hnullify (hnullifier tag isRight) $ g right
220215 }
221216 where
222− htag = HIdentity (hencodeTag tag)
217+ htag = hlabel $ HType $ hencodeTag tag
223218
224219
225220fromColumns2 ::
226221 ( HTable t
227222 , HTable u
228223 , HConstrainTag context EitherTag
229− , HLabelable context
230224 , HNullifiable context
231225 )
232226 => (t context -> a)
@@ -237,12 +231,12 @@ fromColumns2 f g HEitherTable {htag, hleft, hright} = EitherTable
237231 { tag
238232 , left = f $ runIdentity $
239233 hunnullify (\a -> pure . hunnullifier a) $
240− hunlabel hunlabeler
234+ hunlabel
241235 hleft
242236 , right = g $ runIdentity $
243237 hunnullify (\a -> pure . hunnullifier a) $
244− hunlabel hunlabeler
238+ hunlabel
245239 hright
246240 }
247241 where
248− tag = hdecodeTag $ unHIdentity htag
242+ tag = hdecodeTag $ unHIdentity $ hunlabel htag
src/Rel8/Table/Maybe.hs+8−13
@@ -30,9 +30,6 @@ import Prelude hiding ( null, undefined )
3030import Rel8.Expr ( Expr )
3131import Rel8.Expr.Bool ( boolExpr )
3232import Rel8.Expr.Null ( isNull, isNonNull, null, nullify )
33−import Rel8.Schema.Context.Label
34− ( Labelable, HLabelable, hlabeler, hunlabeler
35− )
3633import Rel8.Schema.Context.Nullify
3734 ( Nullifiable, ConstrainTag
3835 , HNullifiable, HConstrainTag
@@ -131,7 +128,7 @@ instance (Table Expr a, Semigroup a) => Monoid (MaybeTable a) where
131128
132129instance
133130 ( Table context a
134− , Labelable context, Nullifiable context
131+ , Nullifiable context
135132 , ConstrainTag context MaybeTag
136133 ) => Table context (MaybeTable a)
137134 where
@@ -145,8 +142,8 @@ instance
145142
146143
147144instance
148− ( Labelable from, Nullifiable from, ConstrainTag from MaybeTag
149− , Labelable to, Nullifiable to, ConstrainTag to MaybeTag
145+ ( Nullifiable from, ConstrainTag from MaybeTag
146+ , Nullifiable to, ConstrainTag to MaybeTag
150147 , Recontextualize from to a b
151148 )
152149 => Recontextualize from to (MaybeTable a) (MaybeTable b)
@@ -222,7 +219,6 @@ nameMaybeTable = MaybeTable . fromName
222219toColumns1 ::
223220 ( HTable t
224221 , HConstrainTag context MaybeTag
225− , HLabelable context
226222 , HNullifiable context
227223 )
228224 => (a -> t context)
@@ -230,25 +226,24 @@ toColumns1 ::
230226 -> HMaybeTable t context
231227toColumns1 f MaybeTable {tag, just} = HMaybeTable
232228 { htag
233− , hjust = hlabel hlabeler $ hnullify (hnullifier tag isNonNull) $ f just
229+ , hjust = hlabel $ hnullify (hnullifier tag isNonNull) $ f just
234230 }
235231 where
236− htag = HIdentity (hencodeTag tag)
232+ htag = hlabel (HType (hencodeTag tag))
237233
238234
239235fromColumns1 ::
240236 ( HTable t
241237 , HConstrainTag context MaybeTag
242− , HLabelable context
243238 , HNullifiable context
244239 )
245240 => (t context -> a)
246241 -> HMaybeTable t context
247242 -> MaybeTable a
248−fromColumns1 f HMaybeTable {htag = HIdentity htag, hjust} = MaybeTable
243+fromColumns1 f HMaybeTable {htag, hjust} = MaybeTable
249244 { tag
250245 , just = f $ runIdentity $
251− hunnullify (\a -> pure . hunnullifier a) (hunlabel hunlabeler hjust)
246+ hunnullify (\a -> pure . hunnullifier a) (hunlabel hjust)
252247 }
253248 where
254− tag = hdecodeTag htag
249+ tag = hdecodeTag (unHIdentity (hunlabel htag))
src/Rel8/Table/Name.hs+6−2
@@ -17,7 +17,8 @@ where
1717-- base
1818import Data.Foldable ( fold )
1919import Data.Functor.Const ( Const( Const ), getConst )
20−import Data.List.NonEmpty ( NonEmpty, intersperse )
20+import Data.List.NonEmpty ( NonEmpty, intersperse, nonEmpty )
21+import Data.Maybe ( fromMaybe )
2122import Prelude
2223
2324-- opaleye
@@ -26,7 +27,6 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
2627-- rel8
2728import Rel8.Expr ( Expr, Col( E ) )
2829import Rel8.Expr.Opaleye ( toPrimExpr )
29−import Rel8.Kind.Labels ( renderLabels )
3030import Rel8.Schema.HTable ( htabulate, htabulateA, hfield, hspecs )
3131import Rel8.Schema.Name ( Name( Name ), Col( N ) )
3232import Rel8.Schema.Spec ( SSpec(..) )
@@ -82,3 +82,7 @@ showNames :: forall a. Table Name a => a -> [String]
8282showNames (toColumns -> names) = getConst $
8383 htabulateA @(Columns a) $ \field -> case hfield names field of
8484 N (Name name) -> Const [name]
85+
86+
87+renderLabels :: [String] -> NonEmpty String
88+renderLabels labels = fromMaybe (pure "anon") (nonEmpty labels )
src/Rel8/Table/Recontextualize.hs+23−6
@@ -18,7 +18,6 @@ import Prelude ()
1818
1919-- rel8
2020import Rel8.Schema.Context ( Col )
21−import Rel8.Schema.Context.Label ( Labelable )
2221import Rel8.Schema.HTable ( HTable )
2322import qualified Rel8.Schema.Kind as K
2423import Rel8.Schema.Null ( Sql )
@@ -54,8 +53,6 @@ instance HTable t => Recontextualize from to (t (Col from)) (t (Col to))
5453instance
5554 ( Recontextualize from to a1 b1
5655 , Recontextualize from to a2 b2
57− , Labelable from
58− , Labelable to
5956 )
6057 => Recontextualize from to (a1, a2) (b1, b2)
6158
@@ -64,7 +61,6 @@ instance
6461 ( Recontextualize from to a1 b1
6562 , Recontextualize from to a2 b2
6663 , Recontextualize from to a3 b3
67− , Labelable from, Labelable to
6864 )
6965 => Recontextualize from to (a1, a2, a3) (b1, b2, b3)
7066
@@ -74,7 +70,6 @@ instance
7470 , Recontextualize from to a2 b2
7571 , Recontextualize from to a3 b3
7672 , Recontextualize from to a4 b4
77− , Labelable from, Labelable to
7873 )
7974 => Recontextualize from to (a1, a2, a3, a4) (b1, b2, b3, b4)
8075
@@ -85,6 +80,28 @@ instance
8580 , Recontextualize from to a3 b3
8681 , Recontextualize from to a4 b4
8782 , Recontextualize from to a5 b5
88− , Labelable from, Labelable to
8983 )
9084 => Recontextualize from to (a1, a2, a3, a4, a5) (b1, b2, b3, b4, b5)
85+
86+
87+instance
88+ ( Recontextualize from to a1 b1
89+ , Recontextualize from to a2 b2
90+ , Recontextualize from to a3 b3
91+ , Recontextualize from to a4 b4
92+ , Recontextualize from to a5 b5
93+ , Recontextualize from to a6 b6
94+ )
95+ => Recontextualize from to (a1, a2, a3, a4, a5, a6) (b1, b2, b3, b4, b5, b6)
96+
97+
98+instance
99+ ( Recontextualize from to a1 b1
100+ , Recontextualize from to a2 b2
101+ , Recontextualize from to a3 b3
102+ , Recontextualize from to a4 b4
103+ , Recontextualize from to a5 b5
104+ , Recontextualize from to a6 b6
105+ , Recontextualize from to a7 b7
106+ )
107+ => Recontextualize from to (a1, a2, a3, a4, a5, a6, a7) (b1, b2, b3, b4, b5, b6, b7)
src/Rel8/Table/Rel8able.hs+8−11
@@ -25,7 +25,7 @@ import qualified Rel8.Kind.Algebra as K
2525import Rel8.Kind.Context
2626 ( SContext( SReify )
2727 , Reifiable, contextSing
28− , sLabelable, sReifiable
28+ , sReifiable
2929 )
3030import Rel8.Generic.Rel8able
3131 ( Rel8able, Algebra
@@ -33,7 +33,6 @@ import Rel8.Generic.Rel8able
3333 , greify, gunreify
3434 )
3535import Rel8.Schema.Context ( Col )
36−import Rel8.Schema.Context.Label ( Labelable )
3736import Rel8.Schema.Dict ( Dict( Dict ) )
3837import qualified Rel8.Schema.Kind as K
3938import Rel8.Schema.HTable ( HConstrainTable, hdicts )
@@ -54,7 +53,7 @@ import Rel8.Type.Eq ( DBEq )
5453import Rel8.Type.Ord ( DBOrd )
5554
5655
57−instance (Rel8able t, Labelable context, Reifiable context) =>
56+instance (Rel8able t, Reifiable context) =>
5857 Table context (t context)
5958 where
6059 type Columns (t context) = GColumns t
@@ -65,20 +64,18 @@ instance (Rel8able t, Labelable context, Reifiable context) =>
6564 toColumns = hunreify . gtoColumns . greify
6665
6766 reify Refl = case contextSing @context of
68− SReify context -> case sLabelable context of
69− Dict -> case sReifiable context of
70− Dict -> greify
67+ SReify context -> case sReifiable context of
68+ Dict -> greify
7169
7270 unreify Refl = case contextSing @context of
73− SReify context -> case sLabelable context of
74− Dict -> case sReifiable context of
75− Dict -> gunreify
71+ SReify context -> case sReifiable context of
72+ Dict -> gunreify
7673
7774
7875instance
7976 ( Rel8able t
80− , Labelable from, Reifiable from
81− , Labelable to, Reifiable to
77+ , Reifiable from
78+ , Reifiable to
8279 , Congruent (t from) (t to)
8380 )
8481 => Recontextualize from to (t from) (t to)
src/Rel8/Table/These.hs+11−17
@@ -36,10 +36,6 @@ import Prelude hiding ( undefined )
3636import Rel8.Expr ( Expr )
3737import Rel8.Expr.Bool ( (&&.), not_ )
3838import Rel8.Expr.Null ( isNonNull )
39−import Rel8.Schema.Context.Label
40− ( Labelable
41− , HLabelable, hlabeler, hunlabeler
42− )
4339import Rel8.Schema.Context.Nullify
4440 ( Nullifiable, ConstrainTag
4541 , HNullifiable, HConstrainTag
@@ -136,7 +132,7 @@ instance (Table Expr a, Table Expr b, Semigroup a, Semigroup b) =>
136132
137133instance
138134 ( Table context a, Table context b
139− , Labelable context, Nullifiable context, ConstrainTag context MaybeTag
135+ , Nullifiable context, ConstrainTag context MaybeTag
140136 ) => Table context (TheseTable a b)
141137 where
142138 type Columns (TheseTable a b) = HTheseTable (Columns a) (Columns b)
@@ -149,8 +145,8 @@ instance
149145
150146
151147instance
152− ( Labelable from, Nullifiable from, ConstrainTag from MaybeTag
153− , Labelable to, Nullifiable to, ConstrainTag to MaybeTag
148+ ( Nullifiable from, ConstrainTag from MaybeTag
149+ , Nullifiable to, ConstrainTag to MaybeTag
154150 , Recontextualize from to a1 b1
155151 , Recontextualize from to a2 b2
156152 ) =>
@@ -285,7 +281,6 @@ toColumns2 ::
285281 ( HTable t
286282 , HTable u
287283 , HConstrainTag context MaybeTag
288− , HLabelable context
289284 , HNullifiable context
290285 )
291286 => (a -> t context)
@@ -293,12 +288,12 @@ toColumns2 ::
293288 -> TheseTable a b
294289 -> HTheseTable t u context
295290toColumns2 f g TheseTable {here, there} = HTheseTable
296− { hhereTag = HIdentity $ hencodeTag (toHereTag (tag here))
291+ { hhereTag = hlabel $ HType $ hencodeTag (toHereTag (tag here))
297292 , hhere =
298− hlabel hlabeler $ hnullify (hnullifier (tag here) isNonNull) $ f (just here)
299− , hthereTag = HIdentity $ hencodeTag (toThereTag (tag there))
293+ hlabel $ hnullify (hnullifier (tag here) isNonNull) $ f (just here)
294+ , hthereTag = hlabel $ HType $ hencodeTag (toThereTag (tag there))
300295 , hthere =
301− hlabel hlabeler $ hnullify (hnullifier (tag there) isNonNull) $ g (just there)
296+ hlabel $ hnullify (hnullifier (tag there) isNonNull) $ g (just there)
302297 }
303298
304299
@@ -306,7 +301,6 @@ fromColumns2 ::
306301 ( HTable t
307302 , HTable u
308303 , HConstrainTag context MaybeTag
309− , HLabelable context
310304 , HNullifiable context
311305 )
312306 => (t context -> a)
@@ -316,26 +310,26 @@ fromColumns2 ::
316310fromColumns2 f g HTheseTable {hhereTag, hhere, hthereTag, hthere} = TheseTable
317311 { here =
318312 let
319− tag = hdecodeTag $ unHIdentity hhereTag
313+ tag = hdecodeTag $ unHIdentity $ hunlabel hhereTag
320314 in
321315 MaybeTable
322316 { tag
323317 , just = f $
324318 runIdentity $
325319 hunnullify (\a -> pure . hunnullifier a) $
326− hunlabel hunlabeler
320+ hunlabel
327321 hhere
328322 }
329323 , there =
330324 let
331− tag = hdecodeTag $ unHIdentity hthereTag
325+ tag = hdecodeTag $ unHIdentity $ hunlabel hthereTag
332326 in
333327 MaybeTable
334328 { tag
335329 , just = g $
336330 runIdentity $
337331 hunnullify (\a -> pure . hunnullifier a) $
338− hunlabel hunlabeler
332+ hunlabel
339333 hthere
340334 }
341335 }