@@ -14,6 +14,7 @@ module Rel8.Table
15 ( Columns, Context, fromColumns, toColumns
15 ( Columns, Context, fromColumns, toColumns
16 , FromExprs, fromResult, toResult
16 , FromExprs, fromResult, toResult
18 , Congruent
19 , Congruent
19 , TTable, TColumns, TContext, TFromExprs
20 , TTable, TColumns, TContext, TFromExprs
@@ -27,7 +28,7 @@ import Prelude hiding ( null )
29import Rel8.FCF ( Eval, Exp )
30import Rel8.FCF ( Eval, Exp )
30−import Rel8.Generic.Map ( GMap )
31+import Rel8.Generic.Map ( GMap, Map )
31import Rel8.Generic.Table.Record
32import Rel8.Generic.Table.Record
32 ( GTable, GColumns, GContext
33 ( GTable, GColumns, GContext
33 , gfromColumns, gtoColumns, gfromResult, gtoResult
34 , gfromColumns, gtoColumns, gfromResult, gtoResult
@@ -52,7 +53,13 @@ import Rel8.Schema.Spec ( KnownSpec )
52-- yourself, as anything that's an instance of 'Rel8.Rel8able' is always a
53-- yourself, as anything that's an instance of 'Rel8.Rel8able' is always a
53-- 'Table'.
54-- 'Table'.
54type Table :: K.Context -> Type -> Constraint
55type Table :: K.Context -> Type -> Constraint
58+ , context ~ Context a
59+ , a ~ Transpose context a
55−class (HTable (Columns a), context ~ Context a) => Table context a | a -> context where
61+ => Table context a | a -> context
56 -- | The 'HTable' functor that describes the schema of this table.
63 -- | The 'HTable' functor that describes the schema of this table.
57 type Columns a :: K.HTable
64 type Columns a :: K.HTable
@@ -63,6 +70,9 @@ class (HTable (Columns a), context ~ Context a) => Table context a | a -> contex
63 -- corresponding Haskell type.
70 -- corresponding Haskell type.
64 type FromExprs a :: Type
71 type FromExprs a :: Type
73+ type Transpose (context' :: K.Context) a :: Type
66 toColumns :: a -> Columns a context
76 toColumns :: a -> Columns a context
67 fromColumns :: Columns a context -> a
77 fromColumns :: Columns a context -> a
@@ -71,7 +81,8 @@ class (HTable (Columns a), context ~ Context a) => Table context a | a -> contex
72 type Columns a = GColumns TColumns (Rep (Record a))
82 type Columns a = GColumns TColumns (Rep (Record a))
73 type Context a = GContext TContext (Rep (Record a))
83 type Context a = GContext TContext (Rep (Record a))
74− type FromExprs a = DefaultFromExprs a
84+ type FromExprs a = Map TFromExprs a
85+ type Transpose context a = Map (TTranspose context) a
76 default toColumns ::
87 default toColumns ::
77 ( Generic (Record a)
88 ( Generic (Record a)
@@ -138,23 +149,6 @@ class (HTable (Columns a), context ~ Context a) => Table context a | a -> contex
138 (\(_ :: proxy x) -> fromResult @(Context x) @x)
149 (\(_ :: proxy x) -> fromResult @(Context x) @x)
141−type DefaultFromExprs :: Type -> Type
142−type family DefaultFromExprs a where
143− DefaultFromExprs (t a b c d e f g) =
144− t (FromExprs a) (FromExprs b) (FromExprs c) (FromExprs d) (FromExprs e)
145− (FromExprs f) (FromExprs g)
146− DefaultFromExprs (t a b c d e f) =
147− t (FromExprs a) (FromExprs b) (FromExprs c) (FromExprs d) (FromExprs e)
149− DefaultFromExprs (t a b c d e) =
150− t (FromExprs a) (FromExprs b) (FromExprs c) (FromExprs d) (FromExprs e)
151− DefaultFromExprs (t a b c d) =
152− t (FromExprs a) (FromExprs b) (FromExprs c) (FromExprs d)
153− DefaultFromExprs (t a b c) = t (FromExprs a) (FromExprs b) (FromExprs c)
154− DefaultFromExprs (t a b) = t (FromExprs a) (FromExprs b)
155− DefaultFromExprs (t a) = t (FromExprs a)
158data TTable :: K.Context -> Type -> Exp Constraint
152data TTable :: K.Context -> Type -> Exp Constraint
159type instance Eval (TTable context a) = Table context a
153type instance Eval (TTable context a) = Table context a
@@ -171,11 +165,16 @@ data TFromExprs :: Type -> Exp Type
171type instance Eval (TFromExprs a) = FromExprs a
165type instance Eval (TFromExprs a) = FromExprs a
168+data TTranspose :: K.Context -> Type -> Exp Type
169+type instance Eval (TTranspose context a) = Transpose context a
174-- | Any context is trivially a table.
172-- | Any context is trivially a table.
175instance KnownSpec spec => Table context (context spec) where
173instance KnownSpec spec => Table context (context spec) where
176 type Columns (context spec) = HIdentity spec
174 type Columns (context spec) = HIdentity spec
177 type Context (context spec) = context
175 type Context (context spec) = context
178 type FromExprs (context spec) = Result spec
176 type FromExprs (context spec) = Result spec
177+ type Transpose to (context spec) = to spec
180 toColumns = HIdentity
179 toColumns = HIdentity
181 fromColumns = unHIdentity
180 fromColumns = unHIdentity