1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language LambdaCase #-}
4{-# language MultiParamTypeClasses #-}
5{-# language ScopedTypeVariables #-}
6{-# language StandaloneKindSignatures #-}
7{-# language TypeApplications #-}
8{-# language TypeFamilies #-}
9{-# language UndecidableInstances #-}
11module Rel8.Column.Lift
17import Data.Functor.Compose ( Compose(..) )
18import Data.Functor.Identity ( Identity(..), runIdentity )
19import Data.Kind ( Type )
20import GHC.Generics ( Rep )
24import Data.Generic.HKD ( Construct, HKD(..), construct, deconstruct )
27import Rel8.Aggregate ( Col(..), Aggregate )
28import Rel8.Expr ( Expr )
29import Rel8.Generic.HKD ( GTable, GColumns, gfromColumns, gtoColumns )
30import Rel8.Kind.Context ( Reifiable(..), SContext(..) )
31import Rel8.Schema.HTable.Type ( HType( HType ) )
32import Rel8.Schema.Insert ( Insert, Col(..) )
33import qualified Rel8.Schema.Kind as K
34import Rel8.Schema.Name ( Name(..) )
35import Rel8.Schema.Reify ( Reify, hreify, hunreify )
36import Rel8.Schema.Result ( Result )
38 ( Table, Columns, Context, fromColumns, toColumns
39 , Unreify, reify, unreify
41import Rel8.Table.Recontextualize ( Recontextualize )
44type Lift :: K.Context -> Type -> Type
45type family Lift context a where
46 Lift (Reify context) a = ALift context a
47 Lift Aggregate a = HKD a (Compose Aggregate Expr)
48 Lift Expr a = HKD a Expr
49 Lift Insert a = HKD a Expr
50 Lift Name a = HKD a Name
54type ALift :: K.Context -> Type -> Type
55newtype ALift context a = ALift
56 { unALift :: Lift context a
63 , Construct Identity a
65 => Table (Reify context) (ALift context a)
67 type Context (ALift context a) = Reify context
68 type Columns (ALift context a) = GColumns (Rep a)
69 type Unreify (ALift context a) = Lift context a
71 fromColumns = sfromColumnsLift contextSing
72 toColumns = stoColumnsLift contextSing
74 unreify _ (ALift a) = a
81 , Construct Identity a
90sfromColumnsLift :: forall a context. (GTable (Rep a), Construct Identity a)
92 -> GColumns (Rep a) (Col (Reify context))
94sfromColumnsLift = \case
98 gfromColumns (\(HType (Aggregation a)) -> Compose a) .
100 SExpr -> ALift . fromColumns . hunreify
104 gfromColumns (\(HType (RequiredInsert a)) -> a) .
106 SName -> ALift . fromColumns . hunreify
107 SResult -> ALift . runIdentity . construct . fromColumns . hunreify
108 SReify context -> ALift . sfromColumnsLift context . hunreify
111stoColumnsLift :: forall a context. (GTable (Rep a), Construct Identity a)
114 -> GColumns (Rep a) (Col (Reify context))
115stoColumnsLift = \case
118 gtoColumns (\(Compose a) -> HType (Aggregation a)) .
121 SExpr -> hreify . toColumns . unALift
124 gtoColumns (HType . RequiredInsert) .
127 SName -> hreify . toColumns . unALift
128 SResult -> hreify . toColumns . deconstruct @Identity . unALift
129 SReify context -> hreify . stoColumnsLift context . unALift
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list