on 97d89cf help sign in
rel8/src/Rel8/Table/Recontextualize.hs
99 lines 2.5 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.Kind ( Constraint, Type )
16import Prelude ()
18-- rel8
19import qualified Rel8.Schema.Kind as K
20import Rel8.Schema.Spec ( KnownSpec )
21import Rel8.Table ( Table, Congruent )
24-- | @Recontextualize from to a b@ is evidence that the types @a@ and @b@ are
25-- related, and that @b@ is the same type as @a@, but after changing the
26-- context from the initial context @from@, to the new context @to@.
27type Recontextualize :: K.Context -> K.Context -> Type -> Type -> Constraint
28class
29 ( Table from a
30 , Table to b
31 , Congruent a b
32 , Recontextualize from from a a
33 , Recontextualize to to b b
34 , Recontextualize to from b a
35 ) => Recontextualize from to a b
36 | a -> from
37 , b -> to
38 , a to -> b
39 , b from -> a
42instance KnownSpec spec => Recontextualize from to (from spec) (to spec)
45instance
46 ( Recontextualize from to a1 b1
47 , Recontextualize from to a2 b2
48 )
49 => Recontextualize from to (a1, a2) (b1, b2)
52instance
53 ( Recontextualize from to a1 b1
54 , Recontextualize from to a2 b2
55 , Recontextualize from to a3 b3
56 )
57 => Recontextualize from to (a1, a2, a3) (b1, b2, b3)
60instance
61 ( Recontextualize from to a1 b1
62 , Recontextualize from to a2 b2
63 , Recontextualize from to a3 b3
64 , Recontextualize from to a4 b4
65 )
66 => Recontextualize from to (a1, a2, a3, a4) (b1, b2, b3, b4)
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 , Recontextualize from to a5 b5
75 )
76 => Recontextualize from to (a1, a2, a3, a4, a5) (b1, b2, b3, b4, b5)
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 , Recontextualize from to a6 b6
86 )
87 => Recontextualize from to (a1, a2, a3, a4, a5, a6) (b1, b2, b3, b4, b5, b6)
90instance
91 ( Recontextualize from to a1 b1
92 , Recontextualize from to a2 b2
93 , Recontextualize from to a3 b3
94 , Recontextualize from to a4 b4
95 , Recontextualize from to a5 b5
96 , Recontextualize from to a6 b6
97 , Recontextualize from to a7 b7
98 )
99 => Recontextualize from to (a1, a2, a3, a4, a5, a6, a7) (b1, b2, b3, b4, b5, b6, b7)