on fb3d2d9 help sign in
rel8/src/Rel8/Table/Recontextualize.hs
90 lines 2.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.Schema.Context ( Col )
21import Rel8.Schema.Context.Label ( Labelable )
22import Rel8.Schema.HTable ( HTable )
23import qualified Rel8.Schema.Kind as K
24import Rel8.Schema.Null ( Sql )
25import Rel8.Schema.Result ( Result )
26import Rel8.Table ( Table, Congruent )
27import Rel8.Type ( DBType )
30type Recontextualize :: K.Context -> K.Context -> Type -> Type -> Constraint
31class
32 ( Table from a
33 , Table to b
34 , Congruent a b
35 , Recontextualize from from a a
36 , Recontextualize to to b b
37 , Recontextualize to from b a
38 ) => Recontextualize from to a b
39 | a -> from
40 , b -> to
41 , a to -> b
42 , b from -> a
45instance Sql DBType a => Recontextualize Result Result (Identity a) (Identity a)
48instance HTable t => Recontextualize from to (t (Col from)) (t (Col to))
51instance
52 ( Table from (t from)
53 , Table to (t to)
54 , Congruent (t from) (t to)
55 ) => Recontextualize from to (t from) (t to)
58instance
59 ( Recontextualize from to a1 b1
60 , Recontextualize from to a2 b2
61 , Labelable from
62 , Labelable to
63 ) => Recontextualize from to (a1, a2) (b1, b2)
66instance
67 ( Recontextualize from to a1 b1
68 , Recontextualize from to a2 b2
69 , Recontextualize from to a3 b3
70 , Labelable from, Labelable to
71 ) => Recontextualize from to (a1, a2, a3) (b1, b2, b3)
74instance
75 ( Recontextualize from to a1 b1
76 , Recontextualize from to a2 b2
77 , Recontextualize from to a3 b3
78 , Recontextualize from to a4 b4
79 , Labelable from, Labelable to
80 ) => Recontextualize from to (a1, a2, a3, a4) (b1, b2, b3, b4)
83instance
84 ( Recontextualize from to a1 b1
85 , Recontextualize from to a2 b2
86 , Recontextualize from to a3 b3
87 , Recontextualize from to a4 b4
88 , Recontextualize from to a5 b5
89 , Labelable from, Labelable to
90 ) => Recontextualize from to (a1, a2, a3, a4, a5) (b1, b2, b3, b4, b5)