on ef28940 help sign in
rel8/src/Rel8/Table/Recontextualize.hs
107 lines 2.8 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.HTable ( HTable )
22import qualified Rel8.Schema.Kind as K
23import Rel8.Schema.Null ( Sql )
24import Rel8.Schema.Result ( Result )
25import Rel8.Table ( Table, Congruent )
26import Rel8.Type ( DBType )
29-- | @Recontextualize from to a b@ is evidence that the types @a@ and @b@ are
30-- related, and that @b@ is the same type as @a@, but after changing the
31-- context from the initial context @from@, to the new context @to@.
32type Recontextualize :: K.Context -> K.Context -> Type -> Type -> Constraint
33class
34 ( Table from a
35 , Table to b
36 , Congruent a b
37 , Recontextualize from from a a
38 , Recontextualize to to b b
39 , Recontextualize to from b a
40 ) => Recontextualize from to a b
41 | a -> from
42 , b -> to
43 , a to -> b
44 , b from -> a
47instance Sql DBType a => Recontextualize Result Result (Identity a) (Identity a)
50instance HTable t => Recontextualize from to (t (Col from)) (t (Col to))
53instance
54 ( Recontextualize from to a1 b1
55 , Recontextualize from to a2 b2
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 )
65 => Recontextualize from to (a1, a2, a3) (b1, b2, b3)
68instance
69 ( Recontextualize from to a1 b1
70 , Recontextualize from to a2 b2
71 , Recontextualize from to a3 b3
72 , Recontextualize from to a4 b4
73 )
74 => Recontextualize from to (a1, a2, a3, a4) (b1, b2, b3, b4)
77instance
78 ( Recontextualize from to a1 b1
79 , Recontextualize from to a2 b2
80 , Recontextualize from to a3 b3
81 , Recontextualize from to a4 b4
82 , Recontextualize from to a5 b5
83 )
84 => Recontextualize from to (a1, a2, a3, a4, a5) (b1, b2, b3, b4, b5)
87instance
88 ( Recontextualize from to a1 b1
89 , Recontextualize from to a2 b2
90 , Recontextualize from to a3 b3
91 , Recontextualize from to a4 b4
92 , Recontextualize from to a5 b5
93 , Recontextualize from to a6 b6
94 )
95 => Recontextualize from to (a1, a2, a3, a4, a5, a6) (b1, b2, b3, b4, b5, b6)
98instance
99 ( Recontextualize from to a1 b1
100 , Recontextualize from to a2 b2
101 , Recontextualize from to a3 b3
102 , Recontextualize from to a4 b4
103 , Recontextualize from to a5 b5
104 , Recontextualize from to a6 b6
105 , Recontextualize from to a7 b7
106 )
107 => Recontextualize from to (a1, a2, a3, a4, a5, a6, a7) (b1, b2, b3, b4, b5, b6, b7)