on be54907 help sign in
rel8/src/Rel8/Table/Recontextualize.hs
143 lines 3.7 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 Data.List.NonEmpty ( NonEmpty)
18import Prelude
20-- rel8
21import Rel8.Schema.Context ( Col )
22import Rel8.Schema.HTable ( HTable )
23import qualified Rel8.Schema.Kind as K
24import Rel8.Schema.Null ( Sql )
25import Rel8.Schema.Result ( Result )
26import Rel8.Schema.Spec ( KnownSpec )
27import Rel8.Table ( Table, Congruent )
28import Rel8.Type ( DBType )
30-- these
31import Data.These ( These)
34-- | @Recontextualize from to a b@ is evidence that the types @a@ and @b@ are
35-- related, and that @b@ is the same type as @a@, but after changing the
36-- context from the initial context @from@, to the new context @to@.
37type Recontextualize :: K.Context -> K.Context -> Type -> Type -> Constraint
38class
39 ( Table from a
40 , Table to b
41 , Congruent a b
42 , Recontextualize from from a a
43 , Recontextualize to to b b
44 , Recontextualize to from b a
45 ) => Recontextualize from to a b
46 | a -> from
47 , b -> to
48 , a to -> b
49 , b from -> a
52instance Sql DBType a => Recontextualize Result Result (Identity a) (Identity a)
55instance KnownSpec spec => Recontextualize from to (Col from spec) (Col to spec)
58instance HTable t => Recontextualize from to (t (Col from)) (t (Col to))
61instance
62 ( Recontextualize from to a1 b1
63 , Recontextualize from to a2 b2
64 , from ~ Result, to ~ Result
65 )
66 => Recontextualize from to (Either a1 a2) (Either b1 b2)
69instance (Recontextualize from to a b, from ~ Result, to ~ Result) =>
70 Recontextualize from to [a] [b]
73instance (Recontextualize from to a b, from ~ Result, to ~ Result) =>
74 Recontextualize from to (Maybe a) (Maybe b)
77instance (Recontextualize from to a b, from ~ Result, to ~ Result) =>
78 Recontextualize from to (NonEmpty a) (NonEmpty b)
81instance
82 ( Recontextualize from to a1 b1
83 , Recontextualize from to a2 b2
84 , from ~ Result, to ~ Result
85 )
86 => Recontextualize from to (These a1 a2) (These b1 b2)
89instance
90 ( Recontextualize from to a1 b1
91 , Recontextualize from to a2 b2
92 )
93 => Recontextualize from to (a1, a2) (b1, b2)
96instance
97 ( Recontextualize from to a1 b1
98 , Recontextualize from to a2 b2
99 , Recontextualize from to a3 b3
100 )
101 => Recontextualize from to (a1, a2, a3) (b1, b2, b3)
104instance
105 ( Recontextualize from to a1 b1
106 , Recontextualize from to a2 b2
107 , Recontextualize from to a3 b3
108 , Recontextualize from to a4 b4
109 )
110 => Recontextualize from to (a1, a2, a3, a4) (b1, b2, b3, b4)
113instance
114 ( Recontextualize from to a1 b1
115 , Recontextualize from to a2 b2
116 , Recontextualize from to a3 b3
117 , Recontextualize from to a4 b4
118 , Recontextualize from to a5 b5
119 )
120 => Recontextualize from to (a1, a2, a3, a4, a5) (b1, b2, b3, b4, b5)
123instance
124 ( Recontextualize from to a1 b1
125 , Recontextualize from to a2 b2
126 , Recontextualize from to a3 b3
127 , Recontextualize from to a4 b4
128 , Recontextualize from to a5 b5
129 , Recontextualize from to a6 b6
130 )
131 => Recontextualize from to (a1, a2, a3, a4, a5, a6) (b1, b2, b3, b4, b5, b6)
134instance
135 ( Recontextualize from to a1 b1
136 , Recontextualize from to a2 b2
137 , Recontextualize from to a3 b3
138 , Recontextualize from to a4 b4
139 , Recontextualize from to a5 b5
140 , Recontextualize from to a6 b6
141 , Recontextualize from to a7 b7
142 )
143 => Recontextualize from to (a1, a2, a3, a4, a5, a6, a7) (b1, b2, b3, b4, b5, b6, b7)