1{-# language AllowAmbiguousTypes #-}
2{-# language DataKinds #-}
3{-# language DisambiguateRecordFields #-}
4{-# language DefaultSignatures #-}
5{-# language FlexibleContexts #-}
6{-# language FlexibleInstances #-}
8{-# language MultiParamTypeClasses #-}
9{-# language ScopedTypeVariables #-}
10{-# language StandaloneKindSignatures #-}
11{-# language TypeApplications #-}
12{-# language TypeFamilies #-}
13{-# language TypeOperators #-}
14{-# language UndecidableInstances #-}
15{-# language ViewPatterns #-}
17{-# options_ghc -fno-warn-orphans #-}
19module Rel8.Schema.Generic
25import Data.Bifunctor ( bimap )
26import Data.Functor.Identity ( Identity )
27import Data.Kind ( Constraint, Type )
28import Data.List.NonEmpty ( NonEmpty )
30 ( Generic, Rep, from, to
31 , (:*:)( (:*:) ), K1( K1 ), M1( M1 )
35import GHC.TypeLits ( Symbol, KnownSymbol )
39import Rel8.Aggregate ( Aggregate )
40import Rel8.Expr ( Expr )
41import Rel8.Kind.Necessity
42 ( SNecessity( SRequired, SOptional )
43 , KnownNecessity, necessitySing
45import Rel8.Schema.Context
46import Rel8.Schema.Context.Identity
47 ( fromHEitherTable, toHEitherTable
48 , fromHListTable, toHListTable
49 , fromHMaybeTable, toHMaybeTable
50 , fromHNonEmptyTable, toHNonEmptyTable
51 , fromHTheseTable, toHTheseTable
53import Rel8.Schema.Context.Label
54 ( Labelable, labeler, unlabeler
55 , hlabeler, hunlabeler
57import Rel8.Schema.Field ( Field )
58import Rel8.Schema.HTable ( HTable )
59import Rel8.Schema.HTable.Either ( HEitherTable )
60import Rel8.Schema.HTable.Identity ( HIdentity(..) )
61import Rel8.Schema.HTable.Label ( HLabel, hlabel, hunlabel )
62import Rel8.Schema.HTable.List ( HListTable )
63import Rel8.Schema.HTable.Maybe ( HMaybeTable )
64import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
65import Rel8.Schema.HTable.Pair ( HPair(..) )
66import Rel8.Schema.HTable.Quartet ( HQuartet(..) )
67import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
68import Rel8.Schema.HTable.These ( HTheseTable )
69import Rel8.Schema.HTable.Trio ( HTrio(..) )
70import Rel8.Schema.HTable.Vectorize ( hrelabel )
71import qualified Rel8.Schema.Kind as K
72import Rel8.Schema.Spec ( Spec( Spec ), KTable )
73import Rel8.Schema.Structure
74 ( IsStructure, Shape(..), Shape1, Shape2
78 ( Table, Columns, Context, fromColumns, toColumns
80import Rel8.Table.Either ( EitherTable )
81import Rel8.Table.Lifted
82 ( fromColumns1, toColumns1
83 , fromColumns2, toColumns2
85import Rel8.Table.List ( ListTable )
86import Rel8.Table.Maybe ( MaybeTable(..) )
87import Rel8.Table.NonEmpty ( NonEmptyTable )
88import Rel8.Table.These ( TheseTable )
91import Data.These ( These )
94instance (Rel8able t, TableHelper context) => Table context (t context) where
95 type Columns (t context) = GRep t
96 type Context (t context) = context
97 fromColumns = gfromColumns
98 toColumns = gtoColumns
101type TableHelper :: K.Context -> Constraint
102class TableHelper context where
103 gfromColumns :: Rel8able t => GRep t (Col context) -> t context
104 gtoColumns :: Rel8able t => t context -> GRep t (Col context)
107instance TableHelper Aggregate where
108 gfromColumns = fromAggregateColumns
109 gtoColumns = toAggregateColumns
112instance TableHelper Expr where
113 gfromColumns = fromExprColumns
114 gtoColumns = toExprColumns
117instance TableHelper Insertion where
118 gfromColumns = fromInsertionColumns
119 gtoColumns = toInsertionColumns
122instance TableHelper Identity where
123 gfromColumns = fromIdentityColumns
124 gtoColumns = toIdentityColumns
127instance TableHelper Name where
128 gfromColumns = fromNameColumns
129 gtoColumns = toNameColumns
132-- | This type class allows you to define custom 'Table's using higher-kinded
133-- data types. Higher-kinded data types are data types of the pattern:
137-- MyType { field1 :: Column f T1 OR HK1 f
138-- , field2 :: Column f T2 OR HK2 f
140-- , fieldN :: Column f Tn OR HKn f
144-- where @Tn@ is any Haskell type, and @HKn@ is any higher-kinded type.
146-- That is, higher-kinded data are records where all fields in the record are
147-- all either of the type @Column f T@ (for any @T@), or are themselves
148-- higher-kinded data:
154-- Nested { nested1 :: MyType f
155-- , nested2 :: MyType f
159-- The @Rel8able@ type class is used to give us a special mapping operation
160-- that lets us change the type parameter @f@.
162-- [Supplying @Rel8able@ instances]
164-- This type class should be derived generically for all table types in your
165-- project. To do this, enable the @DeriveAnyType@ and @DeriveGeneric@ language
169-- \{\-\# LANGUAGE DeriveAnyClass, DeriveGeneric #-\}
171-- data MyType f = MyType { fieldA :: Column f T }
172-- deriving ( GHC.Generics.Generic, Rel8able )
174type Rel8able :: KTable -> Constraint
175class HTable (GRep t) => Rel8able t where
176 type GRep t :: K.HTable
178 fromAggregateColumns :: GRep t (Col Aggregate) -> t Aggregate
179 toAggregateColumns :: t Aggregate -> GRep t (Col Aggregate)
181 fromExprColumns :: GRep t (Col Expr) -> t Expr
182 toExprColumns :: t Expr -> GRep t (Col Expr)
184 fromInsertionColumns :: GRep t (Col Insertion) -> t Insertion
185 toInsertionColumns :: t Insertion -> GRep t (Col Insertion)
187 fromIdentityColumns :: GRep t (Col Identity) -> t Identity
188 toIdentityColumns :: t Identity -> GRep t (Col Identity)
190 fromNameColumns :: GRep t (Col Name) -> t Name
191 toNameColumns :: t Name -> GRep t (Col Name)
193 type GRep t = GColumns (Rep (t Structure))
195 default fromAggregateColumns ::
196 ( Generic (t Aggregate)
197 , GColumns (Rep (t Structure)) ~ GRep t
198 , GRel8able Aggregate (Rep (t Structure)) (Rep (t Aggregate))
199 ) => GRep t (Col Aggregate) -> t Aggregate
200 fromAggregateColumns = to . fromGColumns @_ @(Rep (t Structure))
202 default toAggregateColumns ::
203 ( Generic (t Aggregate)
204 , GColumns (Rep (t Structure)) ~ GRep t
205 , GRel8able Aggregate (Rep (t Structure)) (Rep (t Aggregate))
206 ) => t Aggregate -> GRep t (Col Aggregate)
207 toAggregateColumns = toGColumns @_ @(Rep (t Structure)) . from
209 default fromExprColumns ::
211 , GColumns (Rep (t Structure)) ~ GRep t
212 , GRel8able Expr (Rep (t Structure)) (Rep (t Expr))
213 ) => GRep t (Col Expr) -> t Expr
214 fromExprColumns = to . fromGColumns @_ @(Rep (t Structure))
216 default toExprColumns ::
218 , GColumns (Rep (t Structure)) ~ GRep t
219 , GRel8able Expr (Rep (t Structure)) (Rep (t Expr))
220 ) => t Expr -> GRep t (Col Expr)
221 toExprColumns = toGColumns @_ @(Rep (t Structure)) . from
223 default fromInsertionColumns ::
224 ( Generic (t Insertion)
225 , GColumns (Rep (t Structure)) ~ GRep t
226 , GRel8able Insertion (Rep (t Structure)) (Rep (t Insertion))
227 ) => GRep t (Col Insertion) -> t Insertion
228 fromInsertionColumns = to . fromGColumns @_ @(Rep (t Structure))
230 default toInsertionColumns ::
231 ( Generic (t Insertion)
232 , GColumns (Rep (t Structure)) ~ GRep t
233 , GRel8able Insertion (Rep (t Structure)) (Rep (t Insertion))
234 ) => t Insertion -> GRep t (Col Insertion)
235 toInsertionColumns = toGColumns @_ @(Rep (t Structure)) . from
237 default fromIdentityColumns ::
238 ( Generic (t Identity)
239 , GColumns (Rep (t Structure)) ~ GRep t
240 , GRel8able Identity (Rep (t Structure)) (Rep (t Identity))
241 ) => GRep t (Col Identity) -> t Identity
242 fromIdentityColumns = to . fromGColumns @_ @(Rep (t Structure))
244 default toIdentityColumns ::
245 ( Generic (t Identity)
246 , GColumns (Rep (t Structure)) ~ GRep t
247 , GRel8able Identity (Rep (t Structure)) (Rep (t Identity))
248 ) => t Identity -> GRep t (Col Identity)
249 toIdentityColumns = toGColumns @_ @(Rep (t Structure)) . from
251 default fromNameColumns ::
253 , GColumns (Rep (t Structure)) ~ GRep t
254 , GRel8able Name (Rep (t Structure)) (Rep (t Name))
255 ) => GRep t (Col Name) -> t Name
256 fromNameColumns = to . fromGColumns @_ @(Rep (t Structure))
258 default toNameColumns ::
260 , GColumns (Rep (t Structure)) ~ GRep t
261 , GRel8able Name (Rep (t Structure)) (Rep (t Name))
262 ) => t Name -> GRep t (Col Name)
263 toNameColumns = toGColumns @_ @(Rep (t Structure)) . from
266type GColumns :: (Type -> Type) -> K.HTable
267type family GColumns structure where
268 GColumns (M1 D _ structure) = GColumns structure
269 GColumns (M1 C _ structure) = GColumns structure
270 GColumns (a :*: b) = HPair (GColumns a) (GColumns b)
271 GColumns (M1 S ('MetaSel ('Just label) _ _ _) (K1 _ structure)) =
272 K1Columns label structure
275type GRel8able :: K.Context -> (Type -> Type) -> (Type -> Type) -> Constraint
276class GRel8able context structure rep where
277 fromGColumns :: GColumns structure (Col context) -> rep x
278 toGColumns :: rep x -> GColumns structure (Col context)
281instance GRel8able context structure rep => GRel8able context (M1 D c structure) (M1 D c rep) where
282 fromGColumns = M1 . fromGColumns @context @structure @rep
283 toGColumns (M1 a) = toGColumns @context @structure @rep a
286instance GRel8able context structure rep => GRel8able context (M1 C c structure) (M1 C c rep) where
287 fromGColumns = M1 . fromGColumns @context @structure @rep
288 toGColumns (M1 a) = toGColumns @context @structure @rep a
291instance (GRel8able context structure1 rep1, GRel8able context structure2 rep2) =>
292 GRel8able context (structure1 :*: structure2) (rep1 :*: rep2)
294 fromGColumns (HPair a b) =
295 fromGColumns @context @structure1 @rep1 a :*:
296 fromGColumns @context @structure2 @rep2 b
297 toGColumns (a :*: b) =
299 (toGColumns @context @structure1 @rep1 a)
300 (toGColumns @context @structure2 @rep2 b)
304 ( K1Table label context isStructure structure a
305 , meta ~ 'MetaSel ('Just label) _su _ss _ds
306 , structureK1 ~ K1 i structure
308 ) => GRel8able context (M1 S meta structureK1) (M1 S meta k1)
310 fromGColumns = M1 . K1 . fromK1Columns @label @_ @_ @structure
311 toGColumns (M1 (K1 a)) = toK1Columns @label @_ @_ @structure a
314type K1Columns :: Symbol -> Type -> K.HTable
315type family K1Columns label structure where
316 K1Columns label (Shape1 'Column ('Spec '[] necessity nullability blueprint)) =
317 HIdentity ('Spec '[label] necessity nullability blueprint)
318 K1Columns _label (Shape1 'Column ('Spec (label ': labels) necessity nullability blueprint)) =
319 HIdentity ('Spec (label ': labels) necessity nullability blueprint)
320 K1Columns label (Shape2 'Either a b) =
321 HLabel label (HEitherTable (K1Columns "Left" a) (K1Columns "Right" b))
322 K1Columns label (Shape1 'List a) = HListTable (K1Columns label a)
323 K1Columns label (Shape1 'Maybe a) = HLabel label (HMaybeTable (K1Columns "Just" a))
324 K1Columns label (Shape1 'NonEmpty a) = HNonEmptyTable (K1Columns label a)
325 K1Columns label (Shape2 'These a b) =
326 HLabel label (HTheseTable (K1Columns "Here" a) (K1Columns "There" b))
327 K1Columns label (a, b) =
332 K1Columns label (a, b, c) =
338 K1Columns label (a, b, c, d) =
345 K1Columns label (a, b, c, d, e) =
353 K1Columns label a = HLabel label (Columns a)
356type K1Table :: Symbol -> K.Context -> Bool -> Type -> Type -> Constraint
357class isStructure ~ IsStructure structure =>
358 K1Table label context isStructure structure a
360 fromK1Columns :: K1Columns label structure (Col context) -> a
361 toK1Columns :: a -> K1Columns label structure (Col context)
365 ( x ~ Field Aggregate '[] necessity db a
366 ) => K1Table label Aggregate 'True (Shape1 'Column ('Spec '[] necessity db a)) x
368 fromK1Columns (HIdentity (Aggregation a)) = a
369 toK1Columns = HIdentity . Aggregation
370 {-# INLINABLE fromK1Columns #-}
371 {-# INLINABLE toK1Columns #-}
375 ( x ~ Field Aggregate (label ': labels) necessity db a
376 ) => K1Table _label Aggregate 'True (Shape1 'Column ('Spec (label ': labels) necessity db a)) x
378 fromK1Columns (HIdentity (Aggregation a)) = a
379 toK1Columns = HIdentity . Aggregation
380 {-# INLINABLE fromK1Columns #-}
381 {-# INLINABLE toK1Columns #-}
385 ( x ~ Field Expr '[] necessity db a
386 ) => K1Table label Expr 'True (Shape1 'Column ('Spec '[] necessity db a)) x
388 fromK1Columns (HIdentity (DB a)) = a
389 toK1Columns = HIdentity . DB
390 {-# INLINABLE fromK1Columns #-}
391 {-# INLINABLE toK1Columns #-}
395 ( x ~ Field Expr (label ': labels) necessity db a
396 ) => K1Table _label Expr 'True (Shape1 'Column ('Spec (label ': labels) necessity db a)) x
398 fromK1Columns (HIdentity (DB a)) = a
399 toK1Columns = HIdentity . DB
400 {-# INLINABLE fromK1Columns #-}
401 {-# INLINABLE toK1Columns #-}
405 ( x ~ Field Insertion '[] necessity db a
406 , KnownNecessity necessity
407 ) => K1Table label Insertion 'True (Shape1 'Column ('Spec '[] necessity db a)) x
409 fromK1Columns (HIdentity insert) = case insert of
410 RequiredInsert a -> a
411 OptionalInsert ma -> ma
412 toK1Columns a = HIdentity $ case necessitySing @necessity of
413 SRequired -> RequiredInsert a
414 SOptional -> OptionalInsert a
415 {-# INLINABLE fromK1Columns #-}
416 {-# INLINABLE toK1Columns #-}
420 ( x ~ Field Insertion (label ': labels) necessity db a
421 , KnownNecessity necessity
422 ) => K1Table _label Insertion 'True (Shape1 'Column ('Spec (label ': labels) necessity db a)) x
424 fromK1Columns (HIdentity insert) = case insert of
425 RequiredInsert a -> a
426 OptionalInsert ma -> ma
427 toK1Columns a = HIdentity $ case necessitySing @necessity of
428 SRequired -> RequiredInsert a
429 SOptional -> OptionalInsert a
430 {-# INLINABLE fromK1Columns #-}
431 {-# INLINABLE toK1Columns #-}
435 ( x ~ Field Identity '[] necessity db a
436 ) => K1Table label Identity 'True (Shape1 'Column ('Spec '[] necessity db a)) x
438 fromK1Columns (HIdentity (Result a)) = a
439 toK1Columns = HIdentity . Result
440 {-# INLINABLE fromK1Columns #-}
441 {-# INLINABLE toK1Columns #-}
445 ( x ~ Field Identity (label ': labels) necessity db a
446 ) => K1Table _label Identity 'True (Shape1 'Column ('Spec (label ': labels) necessity db a)) x
448 fromK1Columns (HIdentity (Result a)) = a
449 toK1Columns = HIdentity . Result
450 {-# INLINABLE fromK1Columns #-}
451 {-# INLINABLE toK1Columns #-}
455 ( x ~ Field Name '[] necessity db a
456 ) => K1Table _label Name 'True (Shape1 'Column ('Spec (label ': labels) necessity db a)) x
458 fromK1Columns (HIdentity (NameCol a)) = Name a
459 toK1Columns (Name a) = HIdentity (NameCol a)
460 {-# INLINABLE fromK1Columns #-}
461 {-# INLINABLE toK1Columns #-}
465 ( x ~ Field Name (label ': labels) necessity db a
466 ) => K1Table label Name 'True (Shape1 'Column ('Spec '[] necessity db a)) x
468 fromK1Columns = Name . (\(NameCol a) -> a) . unlabeler . unHIdentity
469 toK1Columns = HIdentity . labeler . NameCol . (\(Name a) -> a)
470 {-# INLINABLE fromK1Columns #-}
471 {-# INLINABLE toK1Columns #-}
475 ( HTable (K1Columns "Left" structure1)
476 , HTable (K1Columns "Right" structure2)
477 , K1Table "Left" Aggregate (IsStructure structure1) structure1 a
478 , K1Table "Right" Aggregate (IsStructure structure2) structure2 b
479 , e ~ EitherTable a b
481 ) => K1Table label Aggregate 'True (Shape2 'Either structure1 structure2) e
485 (fromK1Columns @"Left" @_ @_ @structure1)
486 (fromK1Columns @"Right" @_ @_ @structure2) .
491 (toK1Columns @"Left" @_ @_ @structure1)
492 (toK1Columns @"Right" @_ @_ @structure2)
493 {-# INLINABLE fromK1Columns #-}
494 {-# INLINABLE toK1Columns #-}
498 ( HTable (K1Columns "Left" structure1)
499 , HTable (K1Columns "Right" structure2)
500 , K1Table "Left" Expr (IsStructure structure1) structure1 a
501 , K1Table "Right" Expr (IsStructure structure2) structure2 b
502 , e ~ EitherTable a b
504 ) => K1Table label Expr 'True (Shape2 'Either structure1 structure2) e
508 (fromK1Columns @"Left" @_ @_ @structure1)
509 (fromK1Columns @"Right" @_ @_ @structure2) .
514 (toK1Columns @"Left" @_ @_ @structure1)
515 (toK1Columns @"Right" @_ @_ @structure2)
516 {-# INLINABLE fromK1Columns #-}
517 {-# INLINABLE toK1Columns #-}
521 ( HTable (K1Columns "Left" structure1)
522 , HTable (K1Columns "Right" structure2)
523 , K1Table "Left" Insertion (IsStructure structure1) structure1 a
524 , K1Table "Right" Insertion (IsStructure structure2) structure2 b
525 , e ~ EitherTable a b
527 ) => K1Table label Insertion 'True (Shape2 'Either structure1 structure2) e
531 (fromK1Columns @"Left" @_ @_ @structure1)
532 (fromK1Columns @"Right" @_ @_ @structure2) .
537 (toK1Columns @"Left" @_ @_ @structure1)
538 (toK1Columns @"Right" @_ @_ @structure2)
539 {-# INLINABLE fromK1Columns #-}
540 {-# INLINABLE toK1Columns #-}
544 ( HTable (K1Columns "Left" structure1)
545 , HTable (K1Columns "Right" structure2)
546 , K1Table "Left" Identity (IsStructure structure1) structure1 a
547 , K1Table "Right" Identity (IsStructure structure2) structure2 b
550 ) => K1Table label Identity 'True (Shape2 'Either structure1 structure2) e
554 (fromK1Columns @"Left" @_ @_ @structure1)
555 (fromK1Columns @"Right" @_ @_ @structure2)
562 (toK1Columns @"Left" @_ @_ @structure1)
563 (toK1Columns @"Right" @_ @_ @structure2)
564 {-# INLINABLE fromK1Columns #-}
565 {-# INLINABLE toK1Columns #-}
569 ( HTable (K1Columns "Left" structure1)
570 , HTable (K1Columns "Right" structure2)
571 , K1Table "Left" Name (IsStructure structure1) structure1 a
572 , K1Table "Right" Name (IsStructure structure2) structure2 b
573 , e ~ EitherTable a b
575 ) => K1Table label Name 'True (Shape2 'Either structure1 structure2) e
579 (fromK1Columns @"Left" @_ @_ @structure1)
580 (fromK1Columns @"Right" @_ @_ @structure2) .
585 (toK1Columns @"Left" @_ @_ @structure1)
586 (toK1Columns @"Right" @_ @_ @structure2)
587 {-# INLINABLE fromK1Columns #-}
588 {-# INLINABLE toK1Columns #-}
593 , K1Columns label structure ~ HLabel label (Columns a)
596 ) => K1Table label Aggregate 'True (Shape1 'List structure) as
598 fromK1Columns = fromColumns . hrelabel (hunlabel hunlabeler)
599 toK1Columns = hrelabel (hlabel hlabeler) . toColumns
600 {-# INLINABLE fromK1Columns #-}
601 {-# INLINABLE toK1Columns #-}
606 , K1Columns label structure ~ HLabel label (Columns a)
609 ) => K1Table label Expr 'True (Shape1 'List structure) as
611 fromK1Columns = fromColumns . hrelabel (hunlabel hunlabeler)
612 toK1Columns = hrelabel (hlabel hlabeler) . toColumns
613 {-# INLINABLE fromK1Columns #-}
614 {-# INLINABLE toK1Columns #-}
619 , K1Columns label structure ~ HLabel label (Columns a)
622 ) => K1Table label Insertion 'True (Shape1 'List structure) as
624 fromK1Columns = fromColumns . hrelabel (hunlabel hunlabeler)
625 toK1Columns = hrelabel (hlabel hlabeler) . toColumns
626 {-# INLINABLE fromK1Columns #-}
627 {-# INLINABLE toK1Columns #-}
631 ( K1Table label Identity (IsStructure structure) structure a
632 , HTable (K1Columns label structure)
634 ) => K1Table label Identity 'True (Shape1 'List structure) as
636 fromK1Columns = fmap (fromK1Columns @label @_ @_ @structure) . fromHListTable
637 toK1Columns = toHListTable . fmap (toK1Columns @label @_ @_ @structure)
638 {-# INLINABLE fromK1Columns #-}
639 {-# INLINABLE toK1Columns #-}
644 , K1Columns label structure ~ HLabel label (Columns a)
647 ) => K1Table label Name 'True (Shape1 'List structure) as
649 fromK1Columns = fromColumns . hrelabel (hunlabel hunlabeler)
650 toK1Columns = hrelabel (hlabel hlabeler) . toColumns
651 {-# INLINABLE fromK1Columns #-}
652 {-# INLINABLE toK1Columns #-}
656 ( HTable (K1Columns "Just" structure)
657 , K1Table "Just" Aggregate (IsStructure structure) structure a
660 ) => K1Table label Aggregate 'True (Shape1 'Maybe structure) ma
663 fromColumns1 (fromK1Columns @"Just" @_ @_ @structure) .
667 toColumns1 (toK1Columns @"Just" @_ @_ @structure)
668 {-# INLINABLE fromK1Columns #-}
669 {-# INLINABLE toK1Columns #-}
673 ( HTable (K1Columns "Just" structure)
674 , K1Table "Just" Expr (IsStructure structure) structure a
677 ) => K1Table label Expr 'True (Shape1 'Maybe structure) ma
680 fromColumns1 (fromK1Columns @"Just" @_ @_ @structure) .
684 toColumns1 (toK1Columns @"Just" @_ @_ @structure)
685 {-# INLINABLE fromK1Columns #-}
686 {-# INLINABLE toK1Columns #-}
690 ( HTable (K1Columns "Just" structure)
691 , K1Table "Just" Insertion (IsStructure structure) structure a
694 ) => K1Table label Insertion 'True (Shape1 'Maybe structure) ma
697 fromColumns1 (fromK1Columns @"Just" @_ @_ @structure) .
701 toColumns1 (toK1Columns @"Just" @_ @_ @structure)
702 {-# INLINABLE fromK1Columns #-}
703 {-# INLINABLE toK1Columns #-}
707 ( HTable (K1Columns "Just" structure)
708 , K1Table "Just" Identity (IsStructure structure) structure a
711 ) => K1Table label Identity 'True (Shape1 'Maybe structure) ma
714 = fmap (fromK1Columns @"Just" @_ @_ @structure)
720 . fmap (toK1Columns @"Just" @_ @_ @structure)
721 {-# INLINABLE fromK1Columns #-}
722 {-# INLINABLE toK1Columns #-}
726 ( HTable (K1Columns "Just" structure)
727 , K1Table "Just" Name (IsStructure structure) structure a
730 ) => K1Table label Name 'True (Shape1 'Maybe structure) ma
733 fromColumns1 (fromK1Columns @"Just" @_ @_ @structure) .
737 toColumns1 (toK1Columns @"Just" @_ @_ @structure)
738 {-# INLINABLE fromK1Columns #-}
739 {-# INLINABLE toK1Columns #-}
744 , K1Columns label structure ~ HLabel label (Columns a)
745 , as ~ NonEmptyTable a
747 ) => K1Table label Aggregate 'True (Shape1 'NonEmpty structure) as
749 fromK1Columns = fromColumns . hrelabel (hunlabel hunlabeler)
750 toK1Columns = hrelabel (hlabel hlabeler) . toColumns
751 {-# INLINABLE fromK1Columns #-}
752 {-# INLINABLE toK1Columns #-}
757 , K1Columns label structure ~ HLabel label (Columns a)
758 , as ~ NonEmptyTable a
760 ) => K1Table label Expr 'True (Shape1 'NonEmpty structure) as
762 fromK1Columns = fromColumns . hrelabel (hunlabel hunlabeler)
763 toK1Columns = hrelabel (hlabel hlabeler) . toColumns
764 {-# INLINABLE fromK1Columns #-}
765 {-# INLINABLE toK1Columns #-}
770 , K1Columns label structure ~ HLabel label (Columns a)
771 , as ~ NonEmptyTable a
773 ) => K1Table label Insertion 'True (Shape1 'NonEmpty structure) as
775 fromK1Columns = fromColumns . hrelabel (hunlabel hunlabeler)
776 toK1Columns = hrelabel (hlabel hlabeler) . toColumns
777 {-# INLINABLE fromK1Columns #-}
778 {-# INLINABLE toK1Columns #-}
782 ( K1Table label Identity (IsStructure structure) structure a
783 , HTable (K1Columns label structure)
785 ) => K1Table label Identity 'True (Shape1 'NonEmpty structure) as
787 fromK1Columns = fmap (fromK1Columns @label @_ @_ @structure) . fromHNonEmptyTable
788 toK1Columns = toHNonEmptyTable . fmap (toK1Columns @label @_ @_ @structure)
789 {-# INLINABLE fromK1Columns #-}
790 {-# INLINABLE toK1Columns #-}
795 , K1Columns label structure ~ HLabel label (Columns a)
796 , as ~ NonEmptyTable a
798 ) => K1Table label Name 'True (Shape1 'NonEmpty structure) as
800 fromK1Columns = fromColumns . hrelabel (hunlabel hunlabeler)
801 toK1Columns = hrelabel (hlabel hlabeler) . toColumns
802 {-# INLINABLE fromK1Columns #-}
803 {-# INLINABLE toK1Columns #-}
807 ( HTable (K1Columns "Here" structure1)
808 , HTable (K1Columns "There" structure2)
809 , K1Table "Here" Aggregate (IsStructure structure1) structure1 a
810 , K1Table "There" Aggregate (IsStructure structure2) structure2 b
813 ) => K1Table label Aggregate 'True (Shape2 'These structure1 structure2) e
817 (fromK1Columns @"Here" @_ @_ @structure1)
818 (fromK1Columns @"There" @_ @_ @structure2) .
823 (toK1Columns @"Here" @_ @_ @structure1)
824 (toK1Columns @"There" @_ @_ @structure2)
825 {-# INLINABLE fromK1Columns #-}
826 {-# INLINABLE toK1Columns #-}
830 ( HTable (K1Columns "Here" structure1)
831 , HTable (K1Columns "There" structure2)
832 , K1Table "Here" Expr (IsStructure structure1) structure1 a
833 , K1Table "There" Expr (IsStructure structure2) structure2 b
836 ) => K1Table label Expr 'True (Shape2 'These structure1 structure2) e
840 (fromK1Columns @"Here" @_ @_ @structure1)
841 (fromK1Columns @"There" @_ @_ @structure2) .
846 (toK1Columns @"Here" @_ @_ @structure1)
847 (toK1Columns @"There" @_ @_ @structure2)
848 {-# INLINABLE fromK1Columns #-}
849 {-# INLINABLE toK1Columns #-}
853 ( HTable (K1Columns "Here" structure1)
854 , HTable (K1Columns "There" structure2)
855 , K1Table "Here" Insertion (IsStructure structure1) structure1 a
856 , K1Table "There" Insertion (IsStructure structure2) structure2 b
859 ) => K1Table label Insertion 'True (Shape2 'These structure1 structure2) e
863 (fromK1Columns @"Here" @_ @_ @structure1)
864 (fromK1Columns @"There" @_ @_ @structure2) .
869 (toK1Columns @"Here" @_ @_ @structure1)
870 (toK1Columns @"There" @_ @_ @structure2)
871 {-# INLINABLE fromK1Columns #-}
872 {-# INLINABLE toK1Columns #-}
876 ( HTable (K1Columns "Here" structure1)
877 , HTable (K1Columns "There" structure2)
878 , K1Table "Here" Identity (IsStructure structure1) structure1 a
879 , K1Table "There" Identity (IsStructure structure2) structure2 b
882 ) => K1Table label Identity 'True (Shape2 'These structure1 structure2) e
886 (fromK1Columns @"Here" @_ @_ @structure1)
887 (fromK1Columns @"There" @_ @_ @structure2)
894 (toK1Columns @"Here" @_ @_ @structure1)
895 (toK1Columns @"There" @_ @_ @structure2)
896 {-# INLINABLE fromK1Columns #-}
897 {-# INLINABLE toK1Columns #-}
901 ( HTable (K1Columns "Here" structure1)
902 , HTable (K1Columns "There" structure2)
903 , K1Table "Here" Name (IsStructure structure1) structure1 a
904 , K1Table "There" Name (IsStructure structure2) structure2 b
907 ) => K1Table label Name 'True (Shape2 'These structure1 structure2) e
911 (fromK1Columns @"Here" @_ @_ @structure1)
912 (fromK1Columns @"There" @_ @_ @structure2) .
917 (toK1Columns @"Here" @_ @_ @structure1)
918 (toK1Columns @"There" @_ @_ @structure2)
919 {-# INLINABLE fromK1Columns #-}
920 {-# INLINABLE toK1Columns #-}
924 ( K1Table "fst" context (IsStructure structure1) structure1 a1
925 , K1Table "snd" context (IsStructure structure2) structure2 a2
926 , HTable (K1Columns "fst" structure1)
927 , HTable (K1Columns "snd" structure2)
931 ) => K1Table label context 'True (structure1, structure2) a
933 fromK1Columns (hunlabel unlabeler -> (HPair a b)) =
934 ( fromK1Columns @"fst" @_ @_ @structure1 a
935 , fromK1Columns @"snd" @_ @_ @structure2 b
937 toK1Columns (a, b) = hlabel labeler $ HPair
938 { hfst = toK1Columns @"fst" @_ @_ @structure1 a
939 , hsnd = toK1Columns @"snd" @_ @_ @structure2 b
941 {-# INLINABLE fromK1Columns #-}
942 {-# INLINABLE toK1Columns #-}
946 ( K1Table "fst" context (IsStructure structure1) structure1 a1
947 , K1Table "snd" context (IsStructure structure2) structure2 a2
948 , K1Table "trd" context (IsStructure structure3) structure3 a3
949 , HTable (K1Columns "fst" structure1)
950 , HTable (K1Columns "snd" structure2)
951 , HTable (K1Columns "trd" structure3)
955 ) => K1Table label context 'True (structure1, structure2, structure3) a
957 fromK1Columns (hunlabel unlabeler -> (HTrio a b c)) =
958 ( fromK1Columns @"fst" @_ @_ @structure1 a
959 , fromK1Columns @"snd" @_ @_ @structure2 b
960 , fromK1Columns @"trd" @_ @_ @structure3 c
962 toK1Columns (a, b, c) = hlabel labeler $ HTrio
963 { hfst = toK1Columns @"fst" @_ @_ @structure1 a
964 , hsnd = toK1Columns @"snd" @_ @_ @structure2 b
965 , htrd = toK1Columns @"trd" @_ @_ @structure3 c
967 {-# INLINABLE fromK1Columns #-}
968 {-# INLINABLE toK1Columns #-}
972 ( K1Table "fst" context (IsStructure structure1) structure1 a1
973 , K1Table "snd" context (IsStructure structure2) structure2 a2
974 , K1Table "trd" context (IsStructure structure3) structure3 a3
975 , K1Table "frt" context (IsStructure structure3) structure4 a4
976 , HTable (K1Columns "fst" structure1)
977 , HTable (K1Columns "snd" structure2)
978 , HTable (K1Columns "trd" structure3)
979 , HTable (K1Columns "frt" structure4)
981 , a ~ (a1, a2, a3, a4)
983 ) => K1Table label context 'True (structure1, structure2, structure3, structure4) a
985 fromK1Columns (hunlabel unlabeler -> (HQuartet a b c d)) =
986 ( fromK1Columns @"fst" @_ @_ @structure1 a
987 , fromK1Columns @"snd" @_ @_ @structure2 b
988 , fromK1Columns @"trd" @_ @_ @structure3 c
989 , fromK1Columns @"frt" @_ @_ @structure4 d
991 toK1Columns (a, b, c, d) = hlabel labeler $ HQuartet
992 { hfst = toK1Columns @"fst" @_ @_ @structure1 a
993 , hsnd = toK1Columns @"snd" @_ @_ @structure2 b
994 , htrd = toK1Columns @"trd" @_ @_ @structure3 c
995 , hfrt = toK1Columns @"frt" @_ @_ @structure4 d
997 {-# INLINABLE fromK1Columns #-}
998 {-# INLINABLE toK1Columns #-}
1002 ( K1Table "fst" context (IsStructure structure1) structure1 a1
1003 , K1Table "snd" context (IsStructure structure2) structure2 a2
1004 , K1Table "trd" context (IsStructure structure3) structure3 a3
1005 , K1Table "frt" context (IsStructure structure3) structure4 a4
1006 , K1Table "fft" context (IsStructure structure3) structure5 a5
1007 , HTable (K1Columns "fst" structure1)
1008 , HTable (K1Columns "snd" structure2)
1009 , HTable (K1Columns "trd" structure3)
1010 , HTable (K1Columns "frt" structure4)
1011 , HTable (K1Columns "fft" structure5)
1013 , a ~ (a1, a2, a3, a4, a5)
1015 ) => K1Table label context 'True (structure1, structure2, structure3, structure4, structure5) a
1017 fromK1Columns (hunlabel unlabeler -> (HQuintet a b c d e)) =
1018 ( fromK1Columns @"fst" @_ @_ @structure1 a
1019 , fromK1Columns @"snd" @_ @_ @structure2 b
1020 , fromK1Columns @"trd" @_ @_ @structure3 c
1021 , fromK1Columns @"frt" @_ @_ @structure4 d
1022 , fromK1Columns @"fft" @_ @_ @structure5 e
1024 toK1Columns (a, b, c, d, e) = hlabel labeler $ HQuintet
1025 { hfst = toK1Columns @"fst" @_ @_ @structure1 a
1026 , hsnd = toK1Columns @"snd" @_ @_ @structure2 b
1027 , htrd = toK1Columns @"trd" @_ @_ @structure3 c
1028 , hfrt = toK1Columns @"frt" @_ @_ @structure4 d
1029 , hfft = toK1Columns @"fft" @_ @_ @structure5 e
1031 {-# INLINABLE fromK1Columns #-}
1032 {-# INLINABLE toK1Columns #-}
1036 ( IsStructure structure ~ 'False
1037 , K1Columns label structure ~ HLabel label (Columns structure)
1038 , Columns structure ~ Columns a
1042 ) => K1Table label context 'False structure a
1044 fromK1Columns = fromColumns . hunlabel unlabeler
1045 toK1Columns = hlabel labeler . toColumns
1046 {-# INLINABLE fromK1Columns #-}
1047 {-# INLINABLE toK1Columns #-}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list