1{-# language DataKinds #-}
2{-# language FlexibleInstances #-}
3{-# language FunctionalDependencies #-}
4{-# language ScopedTypeVariables #-}
5{-# language StandaloneKindSignatures #-}
6{-# language TypeApplications #-}
7{-# language TypeFamilies #-}
8{-# language UndecidableInstances #-}
10{-# options_ghc -fno-warn-orphans #-}
12module Rel8.Table.Rel8able
18import Data.Kind ( Constraint )
19import Data.Type.Equality ( (:~:)( Refl ) )
23import Rel8.Expr ( Expr )
24import qualified Rel8.Kind.Algebra as K
25import Rel8.Kind.Context
27 , Reifiable, contextSing
28 , sLabelable, sReifiable
30import Rel8.Generic.Rel8able
32 , GColumns, GContext, gfromColumns, gtoColumns
33 , gfromColumnsADT, gtoColumnsADT
36import Rel8.Schema.Context ( Col )
37import Rel8.Schema.Context.Label ( Labelable )
38import Rel8.Schema.Dict ( Dict( Dict ) )
39import qualified Rel8.Schema.Kind as K
40import Rel8.Schema.HTable ( HConstrainTable, hdicts )
41import Rel8.Schema.Reify ( hreify, hunreify, UnwrapReify )
42import Rel8.Schema.Result ( Result )
44 ( Table, Columns, Context, Congruent, fromColumns, toColumns
45 , Unreify, reify, unreify
47import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
48import Rel8.Table.ADT ( ADT )
49import Rel8.Table.Eq ( EqTable, eqTable )
50import Rel8.Table.Ord ( OrdTable, ordTable )
51import Rel8.Table.Recontextualize ( Recontextualize )
52import Rel8.Table.Serialize ( FromExprs, ToExprs, fromResult, toResult )
53import Rel8.Type.Eq ( DBEq )
54import Rel8.Type.Ord ( DBOrd )
59 , GContext t context ~ context
63 => Table context (t context)
65 type Columns (t context) = GColumns t
66 type Context (t context) = context
67 type Unreify (t context) = t (UnwrapReify context)
69 fromColumns = gunreify . gfromColumns . hreify
70 toColumns = hunreify . gtoColumns . greify
72 reify Refl = case contextSing @context of
73 SReify context -> case sLabelable context of
74 Dict -> case sReifiable context of
77 unreify Refl = case contextSing @context of
78 SReify context -> case sLabelable context of
79 Dict -> case sReifiable context of
85 , Labelable from, Reifiable from, GContext t from ~ from
86 , Labelable to, Reifiable to, GContext t to ~ to
87 , Congruent (t from) (t to)
89 => Recontextualize from to (t from) (t to)
95 , GContext t context ~ context
96 , HConstrainTable (Columns (t context)) (ConstrainDBType DBEq)
98 => EqTable (t context)
100 eqTable = hdicts @(Columns (t context)) @(ConstrainDBType DBEq)
106 , GContext t context ~ context
107 , HConstrainTable (Columns (t context)) (ConstrainDBType DBEq)
108 , HConstrainTable (Columns (t context)) (ConstrainDBType DBOrd)
110 => OrdTable (t context)
112 ordTable = hdicts @(Columns (t context)) @(ConstrainDBType DBOrd)
115type instance FromExprs (t Expr) = FromExprs' t Result
121 , ToExprs' (Algebra t) t' t
123 => ToExprs x (t result)
125 fromResult = fromResult' @(Algebra t) @t'
126 toResult = toResult' @(Algebra t) @t'
129type FromExprs' :: K.Rel8able -> K.Rel8able
130type family FromExprs' t where
131 FromExprs' (ADT t) = t
135type ToExprs' :: K.Algebra -> K.Rel8able -> K.Rel8able -> Constraint
137 ( algebra ~ Algebra t
139 , GContext t' Expr ~ Expr
141 => ToExprs' algebra t' t | algebra t -> t'
143 fromResult' :: GColumns t' (Col Result) -> t Result
144 toResult' :: t Result -> GColumns t' (Col Result)
148 ( Algebra t ~ 'K.Product
150 , GContext t Expr ~ Expr
153 => ToExprs' 'K.Product t' t
155 fromResult' = fromColumns
156 toResult' = toColumns
164 => ToExprs' 'K.Sum t' t
166 fromResult' = gunreify . gfromColumnsADT . hreify
167 toResult' = hunreify . gtoColumnsADT . greify
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