1{-# language AllowAmbiguousTypes #-}
2{-# language ConstraintKinds #-}
3{-# language DataKinds #-}
4{-# language DefaultSignatures #-}
5{-# language FlexibleContexts #-}
6{-# language LambdaCase #-}
7{-# language ScopedTypeVariables #-}
8{-# language StandaloneKindSignatures #-}
9{-# language TypeApplications #-}
10{-# language TypeFamilies #-}
11{-# language TypeFamilyDependencies #-}
12{-# language UndecidableInstances #-}
14module Rel8.Generic.Rel8able
18 , GColumns, gfromColumns, gtoColumns
19 , GFromExprs, gfromResult, gtoResult
24import Data.Kind ( Constraint, Type )
25import GHC.Generics ( Generic, Rep, from, to )
29import Rel8.Aggregate ( Aggregate )
30import Rel8.Expr ( Expr )
31import Rel8.Generic.Map ( GMap )
32import Rel8.Generic.Record ( Record(..) )
33import Rel8.Generic.Table ( GAlgebra )
34import qualified Rel8.Generic.Table.Record as G
35import qualified Rel8.Kind.Algebra as K ( Algebra(..) )
36import Rel8.Schema.Context.Virtual ( Abstract(..) )
37import Rel8.Schema.HTable ( HTable )
38import qualified Rel8.Schema.Kind as K
39import Rel8.Schema.Name ( Name )
40import Rel8.Schema.Result ( Result )
42 ( fromColumns, toColumns, fromResult, toResult
43 , TTable, TColumns, TFromExprs
47-- | The kind of 'Rel8able' types
49type KRel8able = K.Rel8able
52-- | This type class allows you to define custom 'Table's using higher-kinded
53-- data types. Higher-kinded data types are data types of the pattern:
57-- MyType { field1 :: Column f T1 OR HK1 f
58-- , field2 :: Column f T2 OR HK2 f
60-- , fieldN :: Column f Tn OR HKn f
64-- where @Tn@ is any Haskell type, and @HKn@ is any higher-kinded type.
66-- That is, higher-kinded data are records where all fields in the record are
67-- all either of the type @Column f T@ (for any @T@), or are themselves
74-- Nested { nested1 :: MyType f
75-- , nested2 :: MyType f
79-- The @Rel8able@ type class is used to give us a special mapping operation
80-- that lets us change the type parameter @f@.
82-- [Supplying @Rel8able@ instances]
84-- This type class should be derived generically for all table types in your
85-- project. To do this, enable the @DeriveAnyType@ and @DeriveGeneric@ language
89-- \{\-\# LANGUAGE DeriveAnyClass, DeriveGeneric #-\}
91-- data MyType f = MyType { fieldA :: Column f T }
92-- deriving ( GHC.Generics.Generic, Rel8able )
94type Rel8able :: K.Rel8able -> Constraint
95class HTable (GColumns t) => Rel8able t where
96 type GColumns t :: K.HTable
97 type GFromExprs t :: Type
99 gfromColumns :: Abstract context -> GColumns t context -> t context
100 gtoColumns :: Abstract context -> t context -> GColumns t context
102 gfromResult :: GColumns t Result -> GFromExprs t
103 gtoResult :: GFromExprs t -> GColumns t Result
105 type GColumns t = G.GColumns TColumns (GRep t Expr)
106 type GFromExprs t = t Result
108 default gfromColumns :: forall context.
109 ( VRel8able t Aggregate
113 => Abstract context -> GColumns t context -> t context
115 VAggregate -> vfromColumns
116 VExpr -> vfromColumns
117 VName -> vfromColumns
119 default gtoColumns :: forall context.
120 ( VRel8able t Aggregate
124 => Abstract context -> t context -> GColumns t context
126 VAggregate -> vtoColumns
130 default gfromResult ::
131 ( Generic (Record (t Result))
132 , G.GTable (TTable Expr) TColumns TFromExprs (GRep t Expr)
133 , G.GColumns TColumns (GRep t Expr) ~ GColumns t
134 , Rep (Record (t Result)) ~ GMap TFromExprs (GRep t Expr)
135 , GFromExprs t ~ t Result
137 => GColumns t Result -> GFromExprs t
146 (\(_ :: proxy x) -> fromResult @Expr @x)
149 ( Generic (Record (t Result))
150 , G.GTable (TTable Expr) TColumns TFromExprs (GRep t Expr)
151 , G.GColumns TColumns (GRep t Expr) ~ GColumns t
152 , Rep (Record (t Result)) ~ GMap TFromExprs (GRep t Expr)
153 , GFromExprs t ~ t Result
155 => GFromExprs t -> GColumns t Result
162 (\(_ :: proxy x) -> toResult @Expr @x) .
167type Algebra :: K.Rel8able -> K.Algebra
168type Algebra t = GAlgebra (GRep t Expr)
171type GRep :: K.Rel8able -> K.Context -> Type -> Type
172type GRep t context = Rep (Record (t context))
175type VRel8able :: K.Rel8able -> K.Context -> Constraint
176type VRel8able t context =
177 ( Generic (Record (t context))
178 , G.GTable (TTable context) TColumns TFromExprs (GRep t context)
179 , G.GColumns TColumns (GRep t context) ~ GColumns t
183vfromColumns :: forall t context. VRel8able t context
184 => GColumns t context -> t context
188 G.gfromColumns @(TTable context) @TColumns @TFromExprs fromColumns
191vtoColumns :: forall t context. VRel8able t context
192 => t context -> GColumns t context
194 G.gtoColumns @(TTable context) @TColumns @TFromExprs toColumns .
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