on ca7aaef help sign in
rel8/src/Rel8/Table/Recontextualize.hs
133 lines 3.2 kB history raw
1{-# language DataKinds #-}
2{-# language FlexibleInstances #-}
3{-# language FunctionalDependencies #-}
4{-# language StandaloneKindSignatures #-}
5{-# language TypeFamilies #-}
6{-# language UndecidableInstances #-}
7{-# language UndecidableSuperClasses #-}
9module Rel8.Table.Recontextualize
10 ( Recontextualize
11 )
12where
14-- base
15import Data.Functor.Identity ( Identity )
16import Data.Kind ( Constraint, Type )
17import Prelude ()
19-- rel8
20import Rel8.Opaque ( Opaque )
21import Rel8.Schema.Context ( Col )
22import Rel8.Schema.Context.Label ( Labelable )
23import Rel8.Schema.HTable ( HTable )
24import qualified Rel8.Schema.Kind as K
25import Rel8.Schema.Nullability ( Sql )
26import Rel8.Schema.Spec ( KnownSpec )
27import Rel8.Table ( Table, Congruent )
28import Rel8.Type ( DBType )
31type Recontextualize :: K.Context -> K.Context -> Type -> Type -> Constraint
32class
33 ( Table from a
34 , Table to b
35 , Congruent a b
36 , Recontextualize from from a a
37 , Recontextualize to to b b
38 , Recontextualize to from b a
39 ) => Recontextualize from to a b
40 | a -> from
41 , b -> to
42 , a to -> b
43 , b from -> a
46instance KnownSpec spec =>
47 Recontextualize from to (Col from spec) (Col to spec)
50{-
51instance Sql DBType a =>
52 Recontextualize Aggregate Insertion (Aggregate (Expr a)) (Insertion a)
55instance Sql DBType a => Recontextualize Expr Insertion (Expr a) (Insertion a)
56-}
59instance Sql DBType a => Recontextualize Identity Identity (Identity a) (Identity a)
62{-
63instance Sql DBType a =>
64 Recontextualize Identity Insertion (Identity a) (Insertion a)
67instance Sql DBType a =>
68 Recontextualize Insertion Aggregate (Insertion a) (Aggregate (Expr a))
71instance Sql DBType a => Recontextualize Insertion Expr (Insertion a) (Expr a)
74instance Sql DBType a =>
75 Recontextualize Insertion Identity (Insertion a) (Identity a)
78instance Sql DBType a => Recontextualize Insertion Insertion (Insertion a) (Insertion a)
81instance Sql DBType a => Recontextualize Insertion Name (Insertion a) (Name a)
84instance Sql DBType a => Recontextualize Name Insertion (Name a) (Insertion a)
85-}
88instance Recontextualize from to (Opaque from a) (Opaque to a)
91instance HTable t => Recontextualize from to (t (Col from)) (t (Col to))
94instance
95 ( Table from (t from)
96 , Table to (t to)
97 , Congruent (t from) (t to)
98 ) => Recontextualize from to (t from) (t to)
101instance
102 ( Recontextualize from to a1 b1
103 , Recontextualize from to a2 b2
104 , Labelable from
105 , Labelable to
106 ) => Recontextualize from to (a1, a2) (b1, b2)
109instance
110 ( Recontextualize from to a1 b1
111 , Recontextualize from to a2 b2
112 , Recontextualize from to a3 b3
113 , Labelable from, Labelable to
114 ) => Recontextualize from to (a1, a2, a3) (b1, b2, b3)
117instance
118 ( Recontextualize from to a1 b1
119 , Recontextualize from to a2 b2
120 , Recontextualize from to a3 b3
121 , Recontextualize from to a4 b4
122 , Labelable from, Labelable to
123 ) => Recontextualize from to (a1, a2, a3, a4) (b1, b2, b3, b4)
126instance
127 ( Recontextualize from to a1 b1
128 , Recontextualize from to a2 b2
129 , Recontextualize from to a3 b3
130 , Recontextualize from to a4 b4
131 , Recontextualize from to a5 b5
132 , Labelable from, Labelable to
133 ) => Recontextualize from to (a1, a2, a3, a4, a5) (b1, b2, b3, b4, b5)