on 2ba99ea help sign in
rel8/src/Rel8/Table/Recontextualize.hs
90 lines 2.3 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 )
30-- | @Recontextualize from to a b@ is evidence that the types @a@ and @b@ are
31-- related, and that @b@ is the same type as @a@, but after changing the
32-- context from the initial context @from@, to the new context @to@.
33type Recontextualize :: K.Context -> K.Context -> Type -> Type -> Constraint
34class
35 ( Table from a
36 , Table to b
37 , Congruent a b
38 , Recontextualize from from a a
39 , Recontextualize to to b b
40 , Recontextualize to from b a
41 ) => Recontextualize from to a b
42 | a -> from
43 , b -> to
44 , a to -> b
45 , b from -> a
48instance Sql DBType a => Recontextualize Result Result (Identity a) (Identity a)
51instance HTable t => Recontextualize from to (t (Col from)) (t (Col to))
54instance
55 ( Recontextualize from to a1 b1
56 , Recontextualize from to a2 b2
57 , Labelable from
58 , Labelable to
59 )
60 => Recontextualize from to (a1, a2) (b1, b2)
63instance
64 ( Recontextualize from to a1 b1
65 , Recontextualize from to a2 b2
66 , Recontextualize from to a3 b3
67 , Labelable from, Labelable to
68 )
69 => Recontextualize from to (a1, a2, a3) (b1, b2, b3)
72instance
73 ( Recontextualize from to a1 b1
74 , Recontextualize from to a2 b2
75 , Recontextualize from to a3 b3
76 , Recontextualize from to a4 b4
77 , Labelable from, Labelable to
78 )
79 => Recontextualize from to (a1, a2, a3, a4) (b1, b2, b3, b4)
82instance
83 ( Recontextualize from to a1 b1
84 , Recontextualize from to a2 b2
85 , Recontextualize from to a3 b3
86 , Recontextualize from to a4 b4
87 , Recontextualize from to a5 b5
88 , Labelable from, Labelable to
89 )
90 => Recontextualize from to (a1, a2, a3, a4, a5) (b1, b2, b3, b4, b5)