on def349e help sign in
rel8/src/Rel8/Table/Recontextualize.hs
87 lines 2.1 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 ( Recontextualize from to a1 b1
53 , Recontextualize from to a2 b2
54 , Labelable from
55 , Labelable to
56 )
57 => Recontextualize from to (a1, a2) (b1, b2)
60instance
61 ( Recontextualize from to a1 b1
62 , Recontextualize from to a2 b2
63 , Recontextualize from to a3 b3
64 , Labelable from, Labelable to
65 )
66 => Recontextualize from to (a1, a2, a3) (b1, b2, b3)
69instance
70 ( Recontextualize from to a1 b1
71 , Recontextualize from to a2 b2
72 , Recontextualize from to a3 b3
73 , Recontextualize from to a4 b4
74 , Labelable from, Labelable to
75 )
76 => Recontextualize from to (a1, a2, a3, a4) (b1, b2, b3, b4)
79instance
80 ( Recontextualize from to a1 b1
81 , Recontextualize from to a2 b2
82 , Recontextualize from to a3 b3
83 , Recontextualize from to a4 b4
84 , Recontextualize from to a5 b5
85 , Labelable from, Labelable to
86 )
87 => Recontextualize from to (a1, a2, a3, a4, a5) (b1, b2, b3, b4, b5)