{-# language AllowAmbiguousTypes #-}
{-# language DataKinds #-}
{-# language FlexibleContexts #-}
{-# language FlexibleInstances #-}
{-# language MultiParamTypeClasses #-}
{-# language PolyKinds #-}
{-# language RankNTypes #-}
{-# language ScopedTypeVariables #-}
{-# language StandaloneKindSignatures #-}
{-# language TypeApplications #-}
{-# language TypeFamilies #-}
{-# language TypeOperators #-}
{-# language UndecidableInstances #-}

module Rel8.Generic.Table.Record
  ( GTable, GColumns, GContext, gfromColumns, gtoColumns, gtable
  , GToExprs, gfromResult, gtoResult
  )
where

-- base
import Data.Kind ( Constraint, Type )
import Data.Proxy ( Proxy( Proxy ) )
import GHC.Generics
  ( (:*:)( (:*:) ), K1( K1 ), M1( M1 )
  , C, D, S
  , Meta( MetaSel )
  )
import GHC.TypeLits ( KnownSymbol )
import Prelude hiding ( null )

-- rel8
import Rel8.FCF ( Eval, Exp )
import Rel8.Schema.Context ( Col )
import Rel8.Schema.Context.Label ( HLabelable, hlabeler, hunlabeler )
import Rel8.Schema.HTable ( HTable )
import Rel8.Schema.HTable.Label ( HLabel, hlabel, hunlabel )
import Rel8.Schema.HTable.Product ( HProduct(..) )
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Result ( Result )


type GColumns :: (Type -> Exp K.HTable) -> (Type -> Type) -> K.HTable
type family GColumns _Columns rep where
  GColumns _Columns (M1 D _ rep) = GColumns _Columns rep
  GColumns _Columns (M1 C _ rep) = GColumns _Columns rep
  GColumns _Columns (rep1 :*: rep2) =
    HProduct (GColumns _Columns rep1) (GColumns _Columns rep2)
  GColumns _Columns (M1 S ('MetaSel ('Just label) _ _ _) (K1 _ a)) =
    HLabel label (Eval (_Columns a))


type GContext :: (Type -> Exp K.Context) -> (Type -> Type) -> K.Context
type family GContext _Context rep where
  GContext _Context (M1 _ _ rep) = GContext _Context rep
  GContext _Context (rep1 :*: _rep2) = GContext _Context rep1
  GContext _Context (K1 _ a) = Eval (_Context a)


type GTable
  :: (Type -> Exp Constraint)
  -> (Type -> Exp K.HTable)
  -> K.HContext -> (Type -> Type) -> Constraint
class GTable _Table _Columns context rep
 where
  gfromColumns :: ()
    => (forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
    -> GColumns _Columns rep context
    -> rep x

  gtoColumns :: ()
    => (forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
    -> rep x
    -> GColumns _Columns rep context

  gtable :: ()
    => (forall a proxy. Eval (_Table a) => proxy a -> Eval (_Columns a) context)
    -> GColumns _Columns rep context


instance GTable _Table _Columns context rep =>
  GTable _Table _Columns context (M1 D c rep)
 where
  gfromColumns :: (forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns (M1 D c rep) context -> M1 D c rep x
gfromColumns forall a. Eval (_Table a) => Eval (_Columns a) context -> a
fromColumns =
    rep x -> M1 D c rep x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (rep x -> M1 D c rep x)
-> (GColumns _Columns rep context -> rep x)
-> GColumns _Columns rep context
-> M1 D c rep x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns rep context -> rep x
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext) (rep :: * -> *)
       x.
GTable _Table _Columns context rep =>
(forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns rep context -> rep x
gfromColumns @_Table @_Columns @context @rep forall a. Eval (_Table a) => Eval (_Columns a) context -> a
fromColumns
  gtoColumns :: (forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> M1 D c rep x -> GColumns _Columns (M1 D c rep) context
gtoColumns forall a. Eval (_Table a) => a -> Eval (_Columns a) context
toColumns (M1 rep x
a) =
    (forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> rep x -> GColumns _Columns rep context
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext) (rep :: * -> *)
       x.
GTable _Table _Columns context rep =>
(forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> rep x -> GColumns _Columns rep context
gtoColumns @_Table @_Columns @context @rep forall a. Eval (_Table a) => a -> Eval (_Columns a) context
toColumns rep x
a
  gtable :: (forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns (M1 D c rep) context
gtable = GTable _Table _Columns context rep =>
(forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns rep context
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext)
       (rep :: * -> *).
GTable _Table _Columns context rep =>
(forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns rep context
gtable @_Table @_Columns @context @rep


instance GTable _Table _Columns context rep =>
  GTable _Table _Columns context (M1 C c rep)
 where
  gfromColumns :: (forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns (M1 C c rep) context -> M1 C c rep x
gfromColumns forall a. Eval (_Table a) => Eval (_Columns a) context -> a
fromColumns =
    rep x -> M1 C c rep x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (rep x -> M1 C c rep x)
-> (GColumns _Columns rep context -> rep x)
-> GColumns _Columns rep context
-> M1 C c rep x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns rep context -> rep x
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext) (rep :: * -> *)
       x.
GTable _Table _Columns context rep =>
(forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns rep context -> rep x
gfromColumns @_Table @_Columns @context @rep forall a. Eval (_Table a) => Eval (_Columns a) context -> a
fromColumns
  gtoColumns :: (forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> M1 C c rep x -> GColumns _Columns (M1 C c rep) context
gtoColumns forall a. Eval (_Table a) => a -> Eval (_Columns a) context
toColumns (M1 rep x
a) =
    (forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> rep x -> GColumns _Columns rep context
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext) (rep :: * -> *)
       x.
GTable _Table _Columns context rep =>
(forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> rep x -> GColumns _Columns rep context
gtoColumns @_Table @_Columns @context @rep forall a. Eval (_Table a) => a -> Eval (_Columns a) context
toColumns rep x
a
  gtable :: (forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns (M1 C c rep) context
gtable = GTable _Table _Columns context rep =>
(forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns rep context
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext)
       (rep :: * -> *).
GTable _Table _Columns context rep =>
(forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns rep context
gtable @_Table @_Columns @context @rep


instance
  ( GTable _Table _Columns context rep1
  , GTable _Table _Columns context rep2
  )
  => GTable _Table _Columns context (rep1 :*: rep2)
 where
  gfromColumns :: (forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns (rep1 :*: rep2) context -> (:*:) rep1 rep2 x
gfromColumns forall a. Eval (_Table a) => Eval (_Columns a) context -> a
fromColumns (HProduct a b) =
    (forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns rep1 context -> rep1 x
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext) (rep :: * -> *)
       x.
GTable _Table _Columns context rep =>
(forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns rep context -> rep x
gfromColumns @_Table @_Columns @context @rep1 forall a. Eval (_Table a) => Eval (_Columns a) context -> a
fromColumns GColumns _Columns rep1 context
a rep1 x -> rep2 x -> (:*:) rep1 rep2 x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*:
    (forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns rep2 context -> rep2 x
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext) (rep :: * -> *)
       x.
GTable _Table _Columns context rep =>
(forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns rep context -> rep x
gfromColumns @_Table @_Columns @context @rep2 forall a. Eval (_Table a) => Eval (_Columns a) context -> a
fromColumns GColumns _Columns rep2 context
b
  gtoColumns :: (forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> (:*:) rep1 rep2 x -> GColumns _Columns (rep1 :*: rep2) context
gtoColumns forall a. Eval (_Table a) => a -> Eval (_Columns a) context
toColumns (rep1 x
a :*: rep2 x
b) = GColumns _Columns rep1 context
-> GColumns _Columns rep2 context
-> HProduct
     (GColumns _Columns rep1) (GColumns _Columns rep2) context
forall (a :: HTable) (b :: HTable) (context :: HContext).
a context -> b context -> HProduct a b context
HProduct
    ((forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> rep1 x -> GColumns _Columns rep1 context
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext) (rep :: * -> *)
       x.
GTable _Table _Columns context rep =>
(forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> rep x -> GColumns _Columns rep context
gtoColumns @_Table @_Columns @context @rep1 forall a. Eval (_Table a) => a -> Eval (_Columns a) context
toColumns rep1 x
a)
    ((forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> rep2 x -> GColumns _Columns rep2 context
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext) (rep :: * -> *)
       x.
GTable _Table _Columns context rep =>
(forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> rep x -> GColumns _Columns rep context
gtoColumns @_Table @_Columns @context @rep2 forall a. Eval (_Table a) => a -> Eval (_Columns a) context
toColumns rep2 x
b)
  gtable :: (forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns (rep1 :*: rep2) context
gtable forall a (proxy :: * -> *).
Eval (_Table a) =>
proxy a -> Eval (_Columns a) context
table = GColumns _Columns rep1 context
-> GColumns _Columns rep2 context
-> HProduct
     (GColumns _Columns rep1) (GColumns _Columns rep2) context
forall (a :: HTable) (b :: HTable) (context :: HContext).
a context -> b context -> HProduct a b context
HProduct
    ((forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns rep1 context
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext)
       (rep :: * -> *).
GTable _Table _Columns context rep =>
(forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns rep context
gtable @_Table @_Columns @context @rep1 forall a (proxy :: * -> *).
Eval (_Table a) =>
proxy a -> Eval (_Columns a) context
table)
    ((forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns rep2 context
forall (_Table :: * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (context :: HContext)
       (rep :: * -> *).
GTable _Table _Columns context rep =>
(forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns rep context
gtable @_Table @_Columns @context @rep2 forall a (proxy :: * -> *).
Eval (_Table a) =>
proxy a -> Eval (_Columns a) context
table)


instance
  ( HTable (Eval (_Columns a))
  , Eval (_Table a)
  , HLabelable context
  , KnownSymbol label
  , meta ~ 'MetaSel ('Just label) _su _ss _ds
  , k1 ~ K1 i a
  )
  => GTable _Table _Columns context (M1 S meta k1)
 where
  gfromColumns :: (forall a. Eval (_Table a) => Eval (_Columns a) context -> a)
-> GColumns _Columns (M1 S meta k1) context -> M1 S meta k1 x
gfromColumns forall a. Eval (_Table a) => Eval (_Columns a) context -> a
fromColumns = K1 i a x -> M1 S meta (K1 i a) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (K1 i a x -> M1 S meta (K1 i a) x)
-> (HLabel label (Eval (_Columns a)) context -> K1 i a x)
-> HLabel label (Eval (_Columns a)) context
-> M1 S meta (K1 i a) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> K1 i a x
forall k i c (p :: k). c -> K1 i c p
K1 (a -> K1 i a x)
-> (HLabel label (Eval (_Columns a)) context -> a)
-> HLabel label (Eval (_Columns a)) context
-> K1 i a x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eval (_Columns a) context -> a
forall a. Eval (_Table a) => Eval (_Columns a) context -> a
fromColumns (Eval (_Columns a) context -> a)
-> (HLabel label (Eval (_Columns a)) context
    -> Eval (_Columns a) context)
-> HLabel label (Eval (_Columns a)) context
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (labels :: [Symbol]) (necessity :: Necessity) a.
 context ('Spec (label : labels) necessity a)
 -> context ('Spec labels necessity a))
-> HLabel label (Eval (_Columns a)) context
-> Eval (_Columns a) context
forall (t :: HTable) (label :: Symbol) (context :: HContext).
(HTable t, KnownSymbol label) =>
(forall (labels :: [Symbol]) (necessity :: Necessity) a.
 context ('Spec (label : labels) necessity a)
 -> context ('Spec labels necessity a))
-> HLabel label t context -> t context
hunlabel forall (labels :: [Symbol]) (necessity :: Necessity) a.
context ('Spec (label : labels) necessity a)
-> context ('Spec labels necessity a)
forall (context :: HContext) (label :: Symbol) (labels :: [Symbol])
       (necessity :: Necessity) a.
HLabelable context =>
context ('Spec (label : labels) necessity a)
-> context ('Spec labels necessity a)
hunlabeler
  gtoColumns :: (forall a. Eval (_Table a) => a -> Eval (_Columns a) context)
-> M1 S meta k1 x -> GColumns _Columns (M1 S meta k1) context
gtoColumns forall a. Eval (_Table a) => a -> Eval (_Columns a) context
toColumns (M1 (K1 a)) = (forall (labels :: [Symbol]) (necessity :: Necessity) a.
 context ('Spec labels necessity a)
 -> context ('Spec (label : labels) necessity a))
-> Eval (_Columns a) context
-> HLabel label (Eval (_Columns a)) context
forall (t :: HTable) (label :: Symbol) (context :: HContext).
(HTable t, KnownSymbol label) =>
(forall (labels :: [Symbol]) (necessity :: Necessity) a.
 context ('Spec labels necessity a)
 -> context ('Spec (label : labels) necessity a))
-> t context -> HLabel label t context
hlabel forall (labels :: [Symbol]) (necessity :: Necessity) a.
context ('Spec labels necessity a)
-> context ('Spec (label : labels) necessity a)
forall (context :: HContext) (labels :: [Symbol])
       (necessity :: Necessity) a (label :: Symbol).
HLabelable context =>
context ('Spec labels necessity a)
-> context ('Spec (label : labels) necessity a)
hlabeler (a -> Eval (_Columns a) context
forall a. Eval (_Table a) => a -> Eval (_Columns a) context
toColumns a
a)
  gtable :: (forall a (proxy :: * -> *).
 Eval (_Table a) =>
 proxy a -> Eval (_Columns a) context)
-> GColumns _Columns (M1 S meta k1) context
gtable forall a (proxy :: * -> *).
Eval (_Table a) =>
proxy a -> Eval (_Columns a) context
table = (forall (labels :: [Symbol]) (necessity :: Necessity) a.
 context ('Spec labels necessity a)
 -> context ('Spec (label : labels) necessity a))
-> Eval (_Columns a) context
-> HLabel label (Eval (_Columns a)) context
forall (t :: HTable) (label :: Symbol) (context :: HContext).
(HTable t, KnownSymbol label) =>
(forall (labels :: [Symbol]) (necessity :: Necessity) a.
 context ('Spec labels necessity a)
 -> context ('Spec (label : labels) necessity a))
-> t context -> HLabel label t context
hlabel forall (labels :: [Symbol]) (necessity :: Necessity) a.
context ('Spec labels necessity a)
-> context ('Spec (label : labels) necessity a)
forall (context :: HContext) (labels :: [Symbol])
       (necessity :: Necessity) a (label :: Symbol).
HLabelable context =>
context ('Spec labels necessity a)
-> context ('Spec (label : labels) necessity a)
hlabeler (Proxy a -> Eval (_Columns a) context
forall a (proxy :: * -> *).
Eval (_Table a) =>
proxy a -> Eval (_Columns a) context
table (Proxy a
forall k (t :: k). Proxy t
Proxy @a))


type GToExprs
  :: (Type -> Type -> Exp Constraint)
  -> (Type -> Exp K.HTable)
  -> (Type -> Type) -> (Type -> Type) -> Constraint
class GToExprs _ToExprs _Columns exprs rep where
  gfromResult :: ()
    => (forall expr a proxy.
        ( Eval (_ToExprs expr a)
        , HTable (Eval (_Columns expr))
        )
        => proxy expr
        -> Eval (_Columns expr) (Col Result)
        -> a)
    -> GColumns _Columns exprs (Col Result)
    -> rep x
  gtoResult :: ()
    => (forall expr a proxy.
        ( Eval (_ToExprs expr a)
        , HTable (Eval (_Columns expr))
        )
        => proxy expr
        -> a
        -> Eval (_Columns expr) (Col Result))
    -> rep x
    -> GColumns _Columns exprs (Col Result)


instance GToExprs _ToExprs _Columns exprs rep =>
  GToExprs _ToExprs _Columns (M1 D c exprs) (M1 D c rep)
 where
  gfromResult :: (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns (M1 D c exprs) (Col Result) -> M1 D c rep x
gfromResult forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> Eval (_Columns expr) (Col Result) -> a
fromResult =
    rep x -> M1 D c rep x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (rep x -> M1 D c rep x)
-> (GColumns _Columns exprs (Col Result) -> rep x)
-> GColumns _Columns exprs (Col Result)
-> M1 D c rep x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns exprs (Col Result) -> rep x
forall (_ToExprs :: * -> * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (exprs :: * -> *) (rep :: * -> *) x.
GToExprs _ToExprs _Columns exprs rep =>
(forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns exprs (Col Result) -> rep x
gfromResult @_ToExprs @_Columns @exprs forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> Eval (_Columns expr) (Col Result) -> a
fromResult
  gtoResult :: (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> M1 D c rep x -> GColumns _Columns (M1 D c exprs) (Col Result)
gtoResult forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> a -> Eval (_Columns expr) (Col Result)
toResult (M1 rep x
a) =
    (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> rep x -> GColumns _Columns exprs (Col Result)
forall (_ToExprs :: * -> * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (exprs :: * -> *) (rep :: * -> *) x.
GToExprs _ToExprs _Columns exprs rep =>
(forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> rep x -> GColumns _Columns exprs (Col Result)
gtoResult @_ToExprs @_Columns @exprs forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> a -> Eval (_Columns expr) (Col Result)
toResult rep x
a


instance GToExprs _ToExprs _Columns exprs rep =>
  GToExprs _ToExprs _Columns (M1 C c exprs) (M1 C c rep)
 where
  gfromResult :: (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns (M1 C c exprs) (Col Result) -> M1 C c rep x
gfromResult forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> Eval (_Columns expr) (Col Result) -> a
fromResult =
    rep x -> M1 C c rep x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (rep x -> M1 C c rep x)
-> (GColumns _Columns exprs (Col Result) -> rep x)
-> GColumns _Columns exprs (Col Result)
-> M1 C c rep x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns exprs (Col Result) -> rep x
forall (_ToExprs :: * -> * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (exprs :: * -> *) (rep :: * -> *) x.
GToExprs _ToExprs _Columns exprs rep =>
(forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns exprs (Col Result) -> rep x
gfromResult @_ToExprs @_Columns @exprs forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> Eval (_Columns expr) (Col Result) -> a
fromResult
  gtoResult :: (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> M1 C c rep x -> GColumns _Columns (M1 C c exprs) (Col Result)
gtoResult forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> a -> Eval (_Columns expr) (Col Result)
toResult (M1 rep x
a) =
    (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> rep x -> GColumns _Columns exprs (Col Result)
forall (_ToExprs :: * -> * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (exprs :: * -> *) (rep :: * -> *) x.
GToExprs _ToExprs _Columns exprs rep =>
(forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> rep x -> GColumns _Columns exprs (Col Result)
gtoResult @_ToExprs @_Columns @exprs forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> a -> Eval (_Columns expr) (Col Result)
toResult rep x
a


instance
  ( GToExprs _ToExprs _Columns exprs1 rep1
  , GToExprs _ToExprs _Columns exprs2 rep2
  )
  => GToExprs _ToExprs _Columns (exprs1 :*: exprs2) (rep1 :*: rep2)
 where
  gfromResult :: (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns (exprs1 :*: exprs2) (Col Result)
-> (:*:) rep1 rep2 x
gfromResult forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> Eval (_Columns expr) (Col Result) -> a
fromResult (HProduct a b) =
    (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns exprs1 (Col Result) -> rep1 x
forall (_ToExprs :: * -> * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (exprs :: * -> *) (rep :: * -> *) x.
GToExprs _ToExprs _Columns exprs rep =>
(forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns exprs (Col Result) -> rep x
gfromResult @_ToExprs @_Columns @exprs1 forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> Eval (_Columns expr) (Col Result) -> a
fromResult GColumns _Columns exprs1 (Col Result)
a rep1 x -> rep2 x -> (:*:) rep1 rep2 x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*:
    (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns exprs2 (Col Result) -> rep2 x
forall (_ToExprs :: * -> * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (exprs :: * -> *) (rep :: * -> *) x.
GToExprs _ToExprs _Columns exprs rep =>
(forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns exprs (Col Result) -> rep x
gfromResult @_ToExprs @_Columns @exprs2 forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> Eval (_Columns expr) (Col Result) -> a
fromResult GColumns _Columns exprs2 (Col Result)
b
  gtoResult :: (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> (:*:) rep1 rep2 x
-> GColumns _Columns (exprs1 :*: exprs2) (Col Result)
gtoResult forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> a -> Eval (_Columns expr) (Col Result)
toResult (rep1 x
a :*: rep2 x
b) =
    GColumns _Columns exprs1 (Col Result)
-> GColumns _Columns exprs2 (Col Result)
-> HProduct
     (GColumns _Columns exprs1) (GColumns _Columns exprs2) (Col Result)
forall (a :: HTable) (b :: HTable) (context :: HContext).
a context -> b context -> HProduct a b context
HProduct
      ((forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> rep1 x -> GColumns _Columns exprs1 (Col Result)
forall (_ToExprs :: * -> * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (exprs :: * -> *) (rep :: * -> *) x.
GToExprs _ToExprs _Columns exprs rep =>
(forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> rep x -> GColumns _Columns exprs (Col Result)
gtoResult @_ToExprs @_Columns @exprs1 forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> a -> Eval (_Columns expr) (Col Result)
toResult rep1 x
a)
      ((forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> rep2 x -> GColumns _Columns exprs2 (Col Result)
forall (_ToExprs :: * -> * -> Exp Constraint)
       (_Columns :: * -> Exp HTable) (exprs :: * -> *) (rep :: * -> *) x.
GToExprs _ToExprs _Columns exprs rep =>
(forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> rep x -> GColumns _Columns exprs (Col Result)
gtoResult @_ToExprs @_Columns @exprs2 forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> a -> Eval (_Columns expr) (Col Result)
toResult rep2 x
b)


instance
  ( Eval (_ToExprs exprs a)
  , HTable (Eval (_Columns exprs))
  , KnownSymbol label
  , meta ~ 'MetaSel ('Just label) _su _ss _ds
  , k1 ~ K1 i exprs
  , k1' ~ K1 i a
  )
  => GToExprs _ToExprs _Columns (M1 S meta k1) (M1 S meta k1')
 where
  gfromResult :: (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> Eval (_Columns expr) (Col Result) -> a)
-> GColumns _Columns (M1 S meta k1) (Col Result) -> M1 S meta k1' x
gfromResult forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> Eval (_Columns expr) (Col Result) -> a
fromResult =
    K1 i a x -> M1 S meta (K1 i a) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (K1 i a x -> M1 S meta (K1 i a) x)
-> (HLabel label (Eval (_Columns exprs)) (Col Result) -> K1 i a x)
-> HLabel label (Eval (_Columns exprs)) (Col Result)
-> M1 S meta (K1 i a) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> K1 i a x
forall k i c (p :: k). c -> K1 i c p
K1 (a -> K1 i a x)
-> (HLabel label (Eval (_Columns exprs)) (Col Result) -> a)
-> HLabel label (Eval (_Columns exprs)) (Col Result)
-> K1 i a x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy exprs -> Eval (_Columns exprs) (Col Result) -> a
forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> Eval (_Columns expr) (Col Result) -> a
fromResult (Proxy exprs
forall k (t :: k). Proxy t
Proxy @exprs) (Eval (_Columns exprs) (Col Result) -> a)
-> (HLabel label (Eval (_Columns exprs)) (Col Result)
    -> Eval (_Columns exprs) (Col Result))
-> HLabel label (Eval (_Columns exprs)) (Col Result)
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (labels :: [Symbol]) (necessity :: Necessity) a.
 Col Result ('Spec (label : labels) necessity a)
 -> Col Result ('Spec labels necessity a))
-> HLabel label (Eval (_Columns exprs)) (Col Result)
-> Eval (_Columns exprs) (Col Result)
forall (t :: HTable) (label :: Symbol) (context :: HContext).
(HTable t, KnownSymbol label) =>
(forall (labels :: [Symbol]) (necessity :: Necessity) a.
 context ('Spec (label : labels) necessity a)
 -> context ('Spec labels necessity a))
-> HLabel label t context -> t context
hunlabel forall (labels :: [Symbol]) (necessity :: Necessity) a.
Col Result ('Spec (label : labels) necessity a)
-> Col Result ('Spec labels necessity a)
forall (context :: HContext) (label :: Symbol) (labels :: [Symbol])
       (necessity :: Necessity) a.
HLabelable context =>
context ('Spec (label : labels) necessity a)
-> context ('Spec labels necessity a)
hunlabeler
  gtoResult :: (forall expr a (proxy :: * -> *).
 (Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
 proxy expr -> a -> Eval (_Columns expr) (Col Result))
-> M1 S meta k1' x -> GColumns _Columns (M1 S meta k1) (Col Result)
gtoResult forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> a -> Eval (_Columns expr) (Col Result)
toResult (M1 (K1 a)) =
    (forall (labels :: [Symbol]) (necessity :: Necessity) a.
 Col Result ('Spec labels necessity a)
 -> Col Result ('Spec (label : labels) necessity a))
-> Eval (_Columns exprs) (Col Result)
-> HLabel label (Eval (_Columns exprs)) (Col Result)
forall (t :: HTable) (label :: Symbol) (context :: HContext).
(HTable t, KnownSymbol label) =>
(forall (labels :: [Symbol]) (necessity :: Necessity) a.
 context ('Spec labels necessity a)
 -> context ('Spec (label : labels) necessity a))
-> t context -> HLabel label t context
hlabel forall (labels :: [Symbol]) (necessity :: Necessity) a.
Col Result ('Spec labels necessity a)
-> Col Result ('Spec (label : labels) necessity a)
forall (context :: HContext) (labels :: [Symbol])
       (necessity :: Necessity) a (label :: Symbol).
HLabelable context =>
context ('Spec labels necessity a)
-> context ('Spec (label : labels) necessity a)
hlabeler (Proxy exprs -> a -> Eval (_Columns exprs) (Col Result)
forall expr a (proxy :: * -> *).
(Eval (_ToExprs expr a), HTable (Eval (_Columns expr))) =>
proxy expr -> a -> Eval (_Columns expr) (Col Result)
toResult (Proxy exprs
forall k (t :: k). Proxy t
Proxy @exprs) a
a)