@@ -1,7 +1,9 @@
1+{-# language AllowAmbiguousTypes #-}
1{-# language DataKinds #-}
2{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language FlexibleContexts #-}
3{-# language FlexibleInstances #-}
4{-# language FlexibleInstances #-}
4{-# language MultiParamTypeClasses #-}
5{-# language MultiParamTypeClasses #-}
6+{-# language RankNTypes #-}
5{-# language ScopedTypeVariables #-}
7{-# language ScopedTypeVariables #-}
6{-# language StandaloneKindSignatures #-}
8{-# language StandaloneKindSignatures #-}
7{-# language TypeApplications #-}
9{-# language TypeApplications #-}
@@ -10,9 +12,15 @@
10{-# language UndecidableSuperClasses #-}
12{-# language UndecidableSuperClasses #-}
12module Rel8.Table.HKD
14module Rel8.Table.HKD
13− ( HKD( HKD ), HKDT(..)
15+ ( HKD( HKD )
14− , fromHKD, toHKD
16+ , HKDT(..), fromHKD, toHKD, GHKD
15− , GHKD
17+ , ConstructableHKD
18+ , ConstructHKD, constructHKD
19+ , DeconstructHKD, deconstructHKD
20+ , InsertHKD, insertHKD
22+ , AggregateHKD, aggregateHKD
@@ -24,11 +32,20 @@ import GHC.Generics ( Generic, Rep, from, to )
24import Prelude
32import Prelude
35+import Rel8.Aggregate ( Aggregate )
27import Rel8.Column ( Column )
36import Rel8.Column ( Column )
28import Rel8.Expr ( Expr )
37import Rel8.Expr ( Expr )
29import Rel8.FCF ( Eval, Exp )
38import Rel8.FCF ( Eval, Exp )
30import Rel8.Kind.Algebra ( KnownAlgebra )
39import Rel8.Kind.Algebra ( KnownAlgebra )
31import qualified Rel8.Kind.Algebra as K
40import qualified Rel8.Kind.Algebra as K
41+import Rel8.Generic.Construction
43+ , GGConstruct, ggconstruct
44+ , GGDeconstruct, ggdeconstruct
47+ , GGAggregate, ggaggregate
32import Rel8.Generic.Map ( GMap, GMappable, gmap, gunmap )
49import Rel8.Generic.Map ( GMap, GMappable, gmap, gunmap )
33import Rel8.Generic.Record ( GRecord, GRecordable, grecord, gunrecord )
50import Rel8.Generic.Record ( GRecord, GRecordable, grecord, gunrecord )
34import Rel8.Generic.Rel8able
51import Rel8.Generic.Rel8able
@@ -46,6 +63,8 @@ import qualified Rel8.Generic.Table.ADT as G
46import Rel8.Schema.Context ( Col )
63import Rel8.Schema.Context ( Col )
47import qualified Rel8.Schema.Kind as K
64import qualified Rel8.Schema.Kind as K
48import Rel8.Schema.HTable ( HTable )
65import Rel8.Schema.HTable ( HTable )
66+import Rel8.Schema.Insert ( Insert )
67+import Rel8.Schema.Name ( Name )
49import Rel8.Schema.Reify ( Col( Reify ), Reify, hreify, hunreify )
68import Rel8.Schema.Reify ( Col( Reify ), Reify, hreify, hunreify )
50import Rel8.Schema.Result ( Result )
69import Rel8.Schema.Result ( Result )
51import Rel8.Table
70import Rel8.Table
@@ -221,3 +240,57 @@ instance
221 , GMap TUnreify (GMap (TColumn (Reify Result)) (Rep a)) ~ GMap (TColumn Result) (Rep a)
240 , GMap TUnreify (GMap (TColumn (Reify Result)) (Rep a)) ~ GMap (TColumn Result) (Rep a)
223 => GHKD a
242 => GHKD a
245+type ConstructableHKD :: Type -> Constraint
246+class GGConstructable (GAlgebra (Rep a)) (HKDRep a) => ConstructableHKD a
247+instance GGConstructable (GAlgebra (Rep a)) (HKDRep a) => ConstructableHKD a
250+type ConstructHKD :: Type -> Type
251+type ConstructHKD a = GGConstruct (GAlgebra (Rep a)) (HKDRep a) (HKD a Expr)
254+constructHKD :: forall a. ConstructableHKD a => ConstructHKD a
255+constructHKD = ggconstruct @(GAlgebra (Rep a)) @(HKDRep a) @(HKD a Expr) HKD
258+type DeconstructHKD :: Type -> Type -> Type
259+type DeconstructHKD a r = GGDeconstruct (GAlgebra (Rep a)) (HKDRep a) (HKD a Expr) r
262+deconstructHKD :: forall a r. (ConstructableHKD a, Table Expr r)
263+ => DeconstructHKD a r
264+deconstructHKD = ggdeconstruct @(GAlgebra (Rep a)) @(HKDRep a) @(HKD a Expr) @r (\(HKD a) -> a)
267+type InsertHKD :: Type -> Type
268+type InsertHKD a = GGInsert (GAlgebra (Rep a)) (HKDRep a) (HKD a Insert)
271+insertHKD :: forall a. ConstructableHKD a => InsertHKD a
272+insertHKD = gginsert @(GAlgebra (Rep a)) @(HKDRep a) @(HKD a Insert) HKD
275+type NameHKD :: Type -> Type
276+type NameHKD a = GGName (GAlgebra (Rep a)) (HKDRep a) (HKD a Name)
279+nameHKD :: forall a. ConstructableHKD a => NameHKD a
280+nameHKD = ggname @(GAlgebra (Rep a)) @(HKDRep a) @(HKD a Name) HKD
283+type AggregateHKD :: Type -> Type
284+type AggregateHKD a = forall r. GGAggregate (GAlgebra (Rep a)) (HKDRep a) r
287+aggregateHKD :: forall a. ConstructableHKD a
288+ => AggregateHKD a -> HKD a Expr -> Aggregate (HKD a Expr)
290+ ggaggregate @(GAlgebra (Rep a)) @(HKDRep a) @(HKD a Expr) HKD (\(HKD a) -> a)
291+ (f @(Aggregate (HKD a Expr)))
294+data HKDRep :: Type -> K.Context -> Exp (Type -> Type)
295+type instance Eval (HKDRep a context) =
296+ GRecord (GMap (TColumn context) (Rep a))