@@ -1,17 +1,10 @@
1−{-# language AllowAmbiguousTypes #-}
2{-# language DataKinds #-}
1{-# language DataKinds #-}
3−{-# language DisambiguateRecordFields #-}
4{-# language DefaultSignatures #-}
2{-# language DefaultSignatures #-}
5{-# language FlexibleContexts #-}
3{-# language FlexibleContexts #-}
6{-# language FlexibleInstances #-}
4{-# language FlexibleInstances #-}
8{-# language MultiParamTypeClasses #-}
5{-# language MultiParamTypeClasses #-}
9−{-# language QuantifiedConstraints #-}
10−{-# language ScopedTypeVariables #-}
11{-# language StandaloneKindSignatures #-}
6{-# language StandaloneKindSignatures #-}
12−{-# language TypeApplications #-}
13{-# language TypeFamilies #-}
7{-# language TypeFamilies #-}
14−{-# language TypeOperators #-}
15{-# language UndecidableInstances #-}
8{-# language UndecidableInstances #-}
17{-# options_ghc -fno-warn-orphans #-}
10{-# options_ghc -fno-warn-orphans #-}
@@ -24,28 +17,20 @@ where
26import Data.Kind ( Constraint, Type )
19import Data.Kind ( Constraint, Type )
27−import GHC.Generics
20+import GHC.Generics ( Generic, Rep, from, to )
28− ( Generic, Rep, from, to
29− , (:*:)( (:*:) ), K1( K1 ), M1( M1 )
33−import qualified GHC.Generics as G ( C )
34−import GHC.TypeLits ( KnownSymbol )
35import Prelude
21import Prelude
36import Unsafe.Coerce ( unsafeCoerce )
22import Unsafe.Coerce ( unsafeCoerce )
39import Rel8.Schema.Context ( Col )
25import Rel8.Schema.Context ( Col )
40−import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
26+import Rel8.Schema.Context.Label ( Labelable )
41import Rel8.Schema.Field ( Reify, Reifiable, hreify, hunreify )
27import Rel8.Schema.Field ( Reify, Reifiable, hreify, hunreify )
42import Rel8.Schema.HTable ( HTable )
28import Rel8.Schema.HTable ( HTable )
43−import Rel8.Schema.HTable.Label ( HLabel, hlabel, hunlabel )
44−import Rel8.Schema.HTable.Pair ( HPair(..) )
45import qualified Rel8.Schema.Kind as K
29import qualified Rel8.Schema.Kind as K
46import Rel8.Schema.Name ( Name )
30import Rel8.Schema.Name ( Name )
47import Rel8.Table
31import Rel8.Table
48 ( Table, Columns, Context, fromColumns, toColumns
32 ( Table, Columns, Context, fromColumns, toColumns
33+ , GTable, GColumns, fromGColumns, toGColumns
@@ -116,72 +101,25 @@ class HTable (GRep t) => Rel8able t where
116 gtoColumns :: (Labelable context, Reifiable context)
101 gtoColumns :: (Labelable context, Reifiable context)
117 => t (Reify context) -> GRep t (Col (Reify context))
102 => t (Reify context) -> GRep t (Col (Reify context))
119− default gfromColumns :: forall context.
104+ default gfromColumns ::
120 ( Generic (t (Reify context))
105 ( Generic (t (Reify context))
121 , GColumns (Rep (t (Reify context))) ~ GRep t
106 , GColumns (Rep (t (Reify context))) ~ GRep t
122− , GRel8able context (Rep (t (Reify context)))
107+ , GTable (Reify context) (Rep (t (Reify context)))
123 ) => GRep t (Col (Reify context)) -> t (Reify context)
108 ) => GRep t (Col (Reify context)) -> t (Reify context)
124− gfromColumns = to . fromGColumns @_ @(Rep (t (Reify context)))
109+ gfromColumns = to . fromGColumns
126− default gtoColumns :: forall context.
111+ default gtoColumns ::
127 ( Generic (t (Reify context))
112 ( Generic (t (Reify context))
128 , GColumns (Rep (t (Reify context))) ~ GRep t
113 , GColumns (Rep (t (Reify context))) ~ GRep t
129− , GRel8able context (Rep (t (Reify context)))
114+ , GTable (Reify context) (Rep (t (Reify context)))
130 ) => t (Reify context) -> GRep t (Col (Reify context))
115 ) => t (Reify context) -> GRep t (Col (Reify context))
131− gtoColumns = toGColumns @_ @(Rep (t (Reify context))) . from
116+ gtoColumns = toGColumns . from
134type GRep :: K.Table -> K.HTable
119type GRep :: K.Table -> K.HTable
135type GRep t = GColumns (Rep (t (Reify Name)))
120type GRep t = GColumns (Rep (t (Reify Name)))
138−type GColumns :: (Type -> Type) -> K.HTable
139−type family GColumns rep where
140− GColumns (M1 D _ rep) = GColumns rep
141− GColumns (M1 G.C _ rep) = GColumns rep
142− GColumns (rep1 :*: rep2) = HPair (GColumns rep1) (GColumns rep2)
143− GColumns (M1 S ('MetaSel ('Just label) _ _ _) (K1 _ a)) =
144− HLabel label (Columns a)
147−type GRel8able :: K.Context -> (Type -> Type) -> Constraint
148−class GRel8able context rep where
149− fromGColumns :: GColumns rep (Col (Reify context)) -> rep x
150− toGColumns :: rep x -> GColumns rep (Col (Reify context))
153−instance GRel8able context rep => GRel8able context (M1 D c rep) where
154− fromGColumns = M1 . fromGColumns @context @rep
155− toGColumns (M1 a) = toGColumns @context @rep a
158−instance GRel8able context rep => GRel8able context (M1 G.C c rep) where
159− fromGColumns = M1 . fromGColumns @context @rep
160− toGColumns (M1 a) = toGColumns @context @rep a
163−instance (GRel8able context rep1, GRel8able context rep2) =>
164− GRel8able context (rep1 :*: rep2)
166− fromGColumns (HPair a b) =
167− fromGColumns @context @rep1 a :*: fromGColumns @context @rep2 b
168− toGColumns (a :*: b) =
169− HPair (toGColumns @context @rep1 a) (toGColumns @context @rep2 b)
173− ( Table (Reify context) a
176− , GColumns (M1 S meta k1) ~ HLabel label (Columns a)
177− , meta ~ 'MetaSel ('Just label) _su _ss _ds
179− ) => GRel8able context (M1 S meta k1)
181− fromGColumns = M1 . K1 . fromColumns . hunlabel unlabeler
182− toGColumns (M1 (K1 a)) = hlabel labeler (toColumns a)
186 (-- Rel8able t
124 (-- Rel8able t
187 --, forall necessity a. Coercible (Field context necessity a) (AField context necessity a) => Coercible (t context) (t (Reify context))
125 --, forall necessity a. Coercible (Field context necessity a) (AField context necessity a) => Coercible (t context) (t (Reify context))