{-# language DataKinds #-}
{-# language FlexibleContexts #-}
{-# language GADTs #-}
{-# language LambdaCase #-}
{-# language MultiParamTypeClasses #-}
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilies #-}
{-# language UndecidableInstances #-}

module Rel8.Column.Maybe
  ( HMaybe, AHMaybe(..)
  )
where

-- base
import Data.Kind ( Type )
import Prelude

-- rel8
import Rel8.Aggregate ( Aggregate )
import Rel8.Expr ( Expr )
import Rel8.Kind.Context ( SContext(..), Reifiable( contextSing ) )
import Rel8.Schema.Context ( Col )
import Rel8.Schema.HTable.Maybe ( HMaybeTable )
import Rel8.Schema.Insert ( Insert )
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Name ( Name )
import Rel8.Schema.Reify ( Reify, hreify, hunreify )
import Rel8.Schema.Result ( Result )
import Rel8.Table
  ( Table, Columns, Context, fromColumns, toColumns
  , Unreify, reify, unreify
  )
import Rel8.Table.Maybe ( MaybeTable )
import Rel8.Table.Recontextualize ( Recontextualize )


type HMaybe :: K.Context -> Type -> Type
type family HMaybe context where
  HMaybe (Reify context) = AHMaybe context
  HMaybe Aggregate = MaybeTable
  HMaybe Expr = MaybeTable
  HMaybe Insert = MaybeTable
  HMaybe Name = MaybeTable
  HMaybe Result = Maybe


type AHMaybe :: K.Context -> Type -> Type
newtype AHMaybe context a = AHMaybe (HMaybe context a)


instance Reifiable context => Functor (AHMaybe context) where
  fmap :: (a -> b) -> AHMaybe context a -> AHMaybe context b
fmap = SContext context
-> (a -> b) -> AHMaybe context a -> AHMaybe context b
forall (context :: Context) a b.
SContext context
-> (a -> b) -> AHMaybe context a -> AHMaybe context b
smapMaybe SContext context
forall (context :: Context). Reifiable context => SContext context
contextSing


instance (Reifiable context, Table (Reify context) a) =>
  Table (Reify context) (AHMaybe context a)
 where
  type Context (AHMaybe context a) = Reify context
  type Columns (AHMaybe context a) = HMaybeTable (Columns a)
  type Unreify (AHMaybe context a) = HMaybe context (Unreify a)

  fromColumns :: Columns (AHMaybe context a) (Col (Reify context))
-> AHMaybe context a
fromColumns = SContext context
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
forall (context :: Context) a.
Table (Reify context) a =>
SContext context
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
sfromColumnsMaybe SContext context
forall (context :: Context). Reifiable context => SContext context
contextSing
  toColumns :: AHMaybe context a
-> Columns (AHMaybe context a) (Col (Reify context))
toColumns = SContext context
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col (Reify context))
forall (context :: Context) a.
Table (Reify context) a =>
SContext context
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col (Reify context))
stoColumnsMaybe SContext context
forall (context :: Context). Reifiable context => SContext context
contextSing
  reify :: (Reify context :~: Reify ctx)
-> Unreify (AHMaybe context a) -> AHMaybe context a
reify Reify context :~: Reify ctx
proof = ((Unreify a -> a)
 -> AHMaybe context (Unreify a) -> AHMaybe context a)
-> ((Reify context :~: Reify ctx) -> Unreify a -> a)
-> (Reify context :~: Reify ctx)
-> AHMaybe context (Unreify a)
-> AHMaybe context a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Unreify a -> a)
-> AHMaybe context (Unreify a) -> AHMaybe context a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Reify context :~: Reify ctx) -> Unreify a -> a
forall (context :: Context) a (ctx :: Context).
Table context a =>
(context :~: Reify ctx) -> Unreify a -> a
reify Reify context :~: Reify ctx
proof (AHMaybe context (Unreify a) -> AHMaybe context a)
-> (HMaybe context (Unreify a) -> AHMaybe context (Unreify a))
-> HMaybe context (Unreify a)
-> AHMaybe context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybe context (Unreify a) -> AHMaybe context (Unreify a)
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe
  unreify :: (Reify context :~: Reify ctx)
-> AHMaybe context a -> Unreify (AHMaybe context a)
unreify Reify context :~: Reify ctx
proof = (\(AHMaybe HMaybe context (Unreify a)
a) -> HMaybe context (Unreify a)
a) (AHMaybe context (Unreify a) -> HMaybe context (Unreify a))
-> (AHMaybe context a -> AHMaybe context (Unreify a))
-> AHMaybe context a
-> HMaybe context (Unreify a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a -> Unreify a)
 -> AHMaybe context a -> AHMaybe context (Unreify a))
-> ((Reify context :~: Reify ctx) -> a -> Unreify a)
-> (Reify context :~: Reify ctx)
-> AHMaybe context a
-> AHMaybe context (Unreify a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> Unreify a)
-> AHMaybe context a -> AHMaybe context (Unreify a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Reify context :~: Reify ctx) -> a -> Unreify a
forall (context :: Context) a (ctx :: Context).
Table context a =>
(context :~: Reify ctx) -> a -> Unreify a
unreify Reify context :~: Reify ctx
proof


instance
  ( Reifiable context, Reifiable context'
  , Recontextualize (Reify context) (Reify context') a a'
  ) =>
  Recontextualize
    (Reify context)
    (Reify context')
    (AHMaybe context a)
    (AHMaybe context' a')


smapMaybe :: ()
  => SContext context
  -> (a -> b)
  -> AHMaybe context a
  -> AHMaybe context b
smapMaybe :: SContext context
-> (a -> b) -> AHMaybe context a -> AHMaybe context b
smapMaybe = \case
  SContext context
SAggregate -> \a -> b
f (AHMaybe HMaybe context a
a) -> HMaybe context b -> AHMaybe context b
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe ((a -> b) -> MaybeTable a -> MaybeTable b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f MaybeTable a
HMaybe context a
a)
  SContext context
SExpr -> \a -> b
f (AHMaybe HMaybe context a
a) -> HMaybe context b -> AHMaybe context b
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe ((a -> b) -> MaybeTable a -> MaybeTable b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f MaybeTable a
HMaybe context a
a)
  SContext context
SResult -> \a -> b
f (AHMaybe HMaybe context a
a) -> HMaybe context b -> AHMaybe context b
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe ((a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Maybe a
HMaybe context a
a)
  SContext context
SInsert -> \a -> b
f (AHMaybe HMaybe context a
a) -> HMaybe context b -> AHMaybe context b
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe ((a -> b) -> MaybeTable a -> MaybeTable b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f MaybeTable a
HMaybe context a
a)
  SContext context
SName -> \a -> b
f (AHMaybe HMaybe context a
a) -> HMaybe context b -> AHMaybe context b
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe ((a -> b) -> MaybeTable a -> MaybeTable b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f MaybeTable a
HMaybe context a
a)
  SReify SContext context
context -> \a -> b
f (AHMaybe HMaybe context a
a) -> HMaybe context b -> AHMaybe context b
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe (SContext context
-> (a -> b) -> AHMaybe context a -> AHMaybe context b
forall (context :: Context) a b.
SContext context
-> (a -> b) -> AHMaybe context a -> AHMaybe context b
smapMaybe SContext context
context a -> b
f AHMaybe context a
HMaybe context a
a)


sfromColumnsMaybe :: Table (Reify context) a
  => SContext context
  -> HMaybeTable (Columns a) (Col (Reify context))
  -> AHMaybe context a
sfromColumnsMaybe :: SContext context
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
sfromColumnsMaybe = \case
  SContext context
SAggregate -> MaybeTable a -> AHMaybe context a
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe (MaybeTable a -> AHMaybe context a)
-> (HMaybeTable (Columns a) (Col (Reify context)) -> MaybeTable a)
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Columns a (Col Aggregate) -> a)
-> MaybeTable (Columns a (Col Aggregate)) -> MaybeTable a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Columns a (Col (Reify Aggregate)) -> a
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (Columns a (Col (Reify Aggregate)) -> a)
-> (Columns a (Col Aggregate) -> Columns a (Col (Reify Aggregate)))
-> Columns a (Col Aggregate)
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Columns a (Col Aggregate) -> Columns a (Col (Reify Aggregate))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify) (MaybeTable (Columns a (Col Aggregate)) -> MaybeTable a)
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> MaybeTable (Columns a (Col Aggregate)))
-> HMaybeTable (Columns a) (Col (Reify context))
-> MaybeTable a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybeTable (Columns a) (Col context)
-> MaybeTable (Columns a (Col Aggregate))
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (HMaybeTable (Columns a) (Col context)
 -> MaybeTable (Columns a (Col Aggregate)))
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> HMaybeTable (Columns a) (Col context))
-> HMaybeTable (Columns a) (Col (Reify context))
-> MaybeTable (Columns a (Col Aggregate))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybeTable (Columns a) (Col (Reify context))
-> HMaybeTable (Columns a) (Col context)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify
  SContext context
SExpr -> MaybeTable a -> AHMaybe context a
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe (MaybeTable a -> AHMaybe context a)
-> (HMaybeTable (Columns a) (Col (Reify context)) -> MaybeTable a)
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Columns a (Col Expr) -> a)
-> MaybeTable (Columns a (Col Expr)) -> MaybeTable a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Columns a (Col (Reify Expr)) -> a
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (Columns a (Col (Reify Expr)) -> a)
-> (Columns a (Col Expr) -> Columns a (Col (Reify Expr)))
-> Columns a (Col Expr)
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Columns a (Col Expr) -> Columns a (Col (Reify Expr))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify) (MaybeTable (Columns a (Col Expr)) -> MaybeTable a)
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> MaybeTable (Columns a (Col Expr)))
-> HMaybeTable (Columns a) (Col (Reify context))
-> MaybeTable a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybeTable (Columns a) (Col context)
-> MaybeTable (Columns a (Col Expr))
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (HMaybeTable (Columns a) (Col context)
 -> MaybeTable (Columns a (Col Expr)))
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> HMaybeTable (Columns a) (Col context))
-> HMaybeTable (Columns a) (Col (Reify context))
-> MaybeTable (Columns a (Col Expr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybeTable (Columns a) (Col (Reify context))
-> HMaybeTable (Columns a) (Col context)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify
  SContext context
SResult -> Maybe a -> AHMaybe context a
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe (Maybe a -> AHMaybe context a)
-> (HMaybeTable (Columns a) (Col (Reify context)) -> Maybe a)
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Columns a (Col Result) -> a)
-> Maybe (Columns a (Col Result)) -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Columns a (Col (Reify Result)) -> a
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (Columns a (Col (Reify Result)) -> a)
-> (Columns a (Col Result) -> Columns a (Col (Reify Result)))
-> Columns a (Col Result)
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Columns a (Col Result) -> Columns a (Col (Reify Result))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify) (Maybe (Columns a (Col Result)) -> Maybe a)
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> Maybe (Columns a (Col Result)))
-> HMaybeTable (Columns a) (Col (Reify context))
-> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybeTable (Columns a) (Col context)
-> Maybe (Columns a (Col Result))
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (HMaybeTable (Columns a) (Col context)
 -> Maybe (Columns a (Col Result)))
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> HMaybeTable (Columns a) (Col context))
-> HMaybeTable (Columns a) (Col (Reify context))
-> Maybe (Columns a (Col Result))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybeTable (Columns a) (Col (Reify context))
-> HMaybeTable (Columns a) (Col context)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify
  SContext context
SInsert -> MaybeTable a -> AHMaybe context a
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe (MaybeTable a -> AHMaybe context a)
-> (HMaybeTable (Columns a) (Col (Reify context)) -> MaybeTable a)
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Columns a (Col Insert) -> a)
-> MaybeTable (Columns a (Col Insert)) -> MaybeTable a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Columns a (Col (Reify Insert)) -> a
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (Columns a (Col (Reify Insert)) -> a)
-> (Columns a (Col Insert) -> Columns a (Col (Reify Insert)))
-> Columns a (Col Insert)
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Columns a (Col Insert) -> Columns a (Col (Reify Insert))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify) (MaybeTable (Columns a (Col Insert)) -> MaybeTable a)
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> MaybeTable (Columns a (Col Insert)))
-> HMaybeTable (Columns a) (Col (Reify context))
-> MaybeTable a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybeTable (Columns a) (Col context)
-> MaybeTable (Columns a (Col Insert))
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (HMaybeTable (Columns a) (Col context)
 -> MaybeTable (Columns a (Col Insert)))
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> HMaybeTable (Columns a) (Col context))
-> HMaybeTable (Columns a) (Col (Reify context))
-> MaybeTable (Columns a (Col Insert))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybeTable (Columns a) (Col (Reify context))
-> HMaybeTable (Columns a) (Col context)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify
  SContext context
SName -> MaybeTable a -> AHMaybe context a
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe (MaybeTable a -> AHMaybe context a)
-> (HMaybeTable (Columns a) (Col (Reify context)) -> MaybeTable a)
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Columns a (Col Name) -> a)
-> MaybeTable (Columns a (Col Name)) -> MaybeTable a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Columns a (Col (Reify Name)) -> a
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (Columns a (Col (Reify Name)) -> a)
-> (Columns a (Col Name) -> Columns a (Col (Reify Name)))
-> Columns a (Col Name)
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Columns a (Col Name) -> Columns a (Col (Reify Name))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify) (MaybeTable (Columns a (Col Name)) -> MaybeTable a)
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> MaybeTable (Columns a (Col Name)))
-> HMaybeTable (Columns a) (Col (Reify context))
-> MaybeTable a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybeTable (Columns a) (Col context)
-> MaybeTable (Columns a (Col Name))
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (HMaybeTable (Columns a) (Col context)
 -> MaybeTable (Columns a (Col Name)))
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> HMaybeTable (Columns a) (Col context))
-> HMaybeTable (Columns a) (Col (Reify context))
-> MaybeTable (Columns a (Col Name))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HMaybeTable (Columns a) (Col (Reify context))
-> HMaybeTable (Columns a) (Col context)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify
  SReify SContext context
context ->
    AHMaybe context a -> AHMaybe context a
forall (context :: Context) a.
HMaybe context a -> AHMaybe context a
AHMaybe (AHMaybe context a -> AHMaybe context a)
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> AHMaybe context a)
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    SContext context
-> (Columns a (Col (Reify context)) -> a)
-> AHMaybe context (Columns a (Col (Reify context)))
-> AHMaybe context a
forall (context :: Context) a b.
SContext context
-> (a -> b) -> AHMaybe context a -> AHMaybe context b
smapMaybe SContext context
context (Columns a (Col (Reify (Reify context))) -> a
forall (context :: Context) a.
Table context a =>
Columns a (Col context) -> a
fromColumns (Columns a (Col (Reify (Reify context))) -> a)
-> (Columns a (Col (Reify context))
    -> Columns a (Col (Reify (Reify context))))
-> Columns a (Col (Reify context))
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Columns a (Col (Reify context))
-> Columns a (Col (Reify (Reify context)))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify) (AHMaybe context (Columns a (Col (Reify context)))
 -> AHMaybe context a)
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> AHMaybe context (Columns a (Col (Reify context))))
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    SContext context
-> HMaybeTable
     (Columns (Columns a (Col (Reify context)))) (Col (Reify context))
-> AHMaybe context (Columns a (Col (Reify context)))
forall (context :: Context) a.
Table (Reify context) a =>
SContext context
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context a
sfromColumnsMaybe SContext context
context (HMaybeTable (Columns a) (Col context)
 -> AHMaybe context (Columns a (Col (Reify context))))
-> (HMaybeTable (Columns a) (Col (Reify context))
    -> HMaybeTable (Columns a) (Col context))
-> HMaybeTable (Columns a) (Col (Reify context))
-> AHMaybe context (Columns a (Col (Reify context)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    HMaybeTable (Columns a) (Col (Reify context))
-> HMaybeTable (Columns a) (Col context)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify


stoColumnsMaybe :: Table (Reify context) a
  => SContext context
  -> AHMaybe context a
  -> HMaybeTable (Columns a) (Col (Reify context))
stoColumnsMaybe :: SContext context
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col (Reify context))
stoColumnsMaybe = \case
  SContext context
SAggregate ->
    HMaybeTable (Columns a) (Col context)
-> HMaybeTable (Columns a) (Col (Reify context))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify (HMaybeTable (Columns a) (Col context)
 -> HMaybeTable (Columns a) (Col (Reify context)))
-> (AHMaybe context a -> HMaybeTable (Columns a) (Col context))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col (Reify context))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeTable (Columns a (Col Aggregate))
-> HMaybeTable (Columns a) (Col context)
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns (MaybeTable (Columns a (Col Aggregate))
 -> HMaybeTable (Columns a) (Col context))
-> (AHMaybe context a -> MaybeTable (Columns a (Col Aggregate)))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col context)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Columns a (Col Aggregate))
-> MaybeTable a -> MaybeTable (Columns a (Col Aggregate))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Columns a (Col (Reify Aggregate)) -> Columns a (Col Aggregate)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify (Columns a (Col (Reify Aggregate)) -> Columns a (Col Aggregate))
-> (a -> Columns a (Col (Reify Aggregate)))
-> a
-> Columns a (Col Aggregate)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Columns a (Col (Reify Aggregate))
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns) (MaybeTable a -> MaybeTable (Columns a (Col Aggregate)))
-> (AHMaybe context a -> MaybeTable a)
-> AHMaybe context a
-> MaybeTable (Columns a (Col Aggregate))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(AHMaybe HMaybe context a
a) -> MaybeTable a
HMaybe context a
a)
  SContext context
SExpr ->
    HMaybeTable (Columns a) (Col context)
-> HMaybeTable (Columns a) (Col (Reify context))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify (HMaybeTable (Columns a) (Col context)
 -> HMaybeTable (Columns a) (Col (Reify context)))
-> (AHMaybe context a -> HMaybeTable (Columns a) (Col context))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col (Reify context))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeTable (Columns a (Col Expr))
-> HMaybeTable (Columns a) (Col context)
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns (MaybeTable (Columns a (Col Expr))
 -> HMaybeTable (Columns a) (Col context))
-> (AHMaybe context a -> MaybeTable (Columns a (Col Expr)))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col context)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Columns a (Col Expr))
-> MaybeTable a -> MaybeTable (Columns a (Col Expr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Columns a (Col (Reify Expr)) -> Columns a (Col Expr)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify (Columns a (Col (Reify Expr)) -> Columns a (Col Expr))
-> (a -> Columns a (Col (Reify Expr))) -> a -> Columns a (Col Expr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Columns a (Col (Reify Expr))
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns) (MaybeTable a -> MaybeTable (Columns a (Col Expr)))
-> (AHMaybe context a -> MaybeTable a)
-> AHMaybe context a
-> MaybeTable (Columns a (Col Expr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(AHMaybe HMaybe context a
a) -> MaybeTable a
HMaybe context a
a)
  SContext context
SResult ->
    HMaybeTable (Columns a) (Col context)
-> HMaybeTable (Columns a) (Col (Reify context))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify (HMaybeTable (Columns a) (Col context)
 -> HMaybeTable (Columns a) (Col (Reify context)))
-> (AHMaybe context a -> HMaybeTable (Columns a) (Col context))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col (Reify context))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (Columns a (Col Result))
-> HMaybeTable (Columns a) (Col context)
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns (Maybe (Columns a (Col Result))
 -> HMaybeTable (Columns a) (Col context))
-> (AHMaybe context a -> Maybe (Columns a (Col Result)))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col context)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Columns a (Col Result))
-> Maybe a -> Maybe (Columns a (Col Result))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Columns a (Col (Reify Result)) -> Columns a (Col Result)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify (Columns a (Col (Reify Result)) -> Columns a (Col Result))
-> (a -> Columns a (Col (Reify Result)))
-> a
-> Columns a (Col Result)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Columns a (Col (Reify Result))
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns) (Maybe a -> Maybe (Columns a (Col Result)))
-> (AHMaybe context a -> Maybe a)
-> AHMaybe context a
-> Maybe (Columns a (Col Result))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(AHMaybe HMaybe context a
a) -> Maybe a
HMaybe context a
a)
  SContext context
SInsert ->
    HMaybeTable (Columns a) (Col context)
-> HMaybeTable (Columns a) (Col (Reify context))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify (HMaybeTable (Columns a) (Col context)
 -> HMaybeTable (Columns a) (Col (Reify context)))
-> (AHMaybe context a -> HMaybeTable (Columns a) (Col context))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col (Reify context))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeTable (Columns a (Col Insert))
-> HMaybeTable (Columns a) (Col context)
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns (MaybeTable (Columns a (Col Insert))
 -> HMaybeTable (Columns a) (Col context))
-> (AHMaybe context a -> MaybeTable (Columns a (Col Insert)))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col context)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Columns a (Col Insert))
-> MaybeTable a -> MaybeTable (Columns a (Col Insert))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Columns a (Col (Reify Insert)) -> Columns a (Col Insert)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify (Columns a (Col (Reify Insert)) -> Columns a (Col Insert))
-> (a -> Columns a (Col (Reify Insert)))
-> a
-> Columns a (Col Insert)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Columns a (Col (Reify Insert))
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns) (MaybeTable a -> MaybeTable (Columns a (Col Insert)))
-> (AHMaybe context a -> MaybeTable a)
-> AHMaybe context a
-> MaybeTable (Columns a (Col Insert))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(AHMaybe HMaybe context a
a) -> MaybeTable a
HMaybe context a
a)
  SContext context
SName ->
    HMaybeTable (Columns a) (Col context)
-> HMaybeTable (Columns a) (Col (Reify context))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify (HMaybeTable (Columns a) (Col context)
 -> HMaybeTable (Columns a) (Col (Reify context)))
-> (AHMaybe context a -> HMaybeTable (Columns a) (Col context))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col (Reify context))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeTable (Columns a (Col Name))
-> HMaybeTable (Columns a) (Col context)
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns (MaybeTable (Columns a (Col Name))
 -> HMaybeTable (Columns a) (Col context))
-> (AHMaybe context a -> MaybeTable (Columns a (Col Name)))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col context)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Columns a (Col Name))
-> MaybeTable a -> MaybeTable (Columns a (Col Name))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Columns a (Col (Reify Name)) -> Columns a (Col Name)
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify (Columns a (Col (Reify Name)) -> Columns a (Col Name))
-> (a -> Columns a (Col (Reify Name))) -> a -> Columns a (Col Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Columns a (Col (Reify Name))
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns) (MaybeTable a -> MaybeTable (Columns a (Col Name)))
-> (AHMaybe context a -> MaybeTable a)
-> AHMaybe context a
-> MaybeTable (Columns a (Col Name))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(AHMaybe HMaybe context a
a) -> MaybeTable a
HMaybe context a
a)
  SReify SContext context
context ->
    HMaybeTable (Columns a) (Col context)
-> HMaybeTable (Columns a) (Col (Reify context))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col context) -> t (Col (Reify context))
hreify (HMaybeTable (Columns a) (Col context)
 -> HMaybeTable (Columns a) (Col (Reify context)))
-> (AHMaybe context a -> HMaybeTable (Columns a) (Col context))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col (Reify context))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    SContext context
-> AHMaybe context (Columns a (Col (Reify context)))
-> HMaybeTable
     (Columns (Columns a (Col (Reify context)))) (Col (Reify context))
forall (context :: Context) a.
Table (Reify context) a =>
SContext context
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col (Reify context))
stoColumnsMaybe SContext context
context (AHMaybe context (Columns a (Col (Reify context)))
 -> HMaybeTable (Columns a) (Col context))
-> (AHMaybe context a
    -> AHMaybe context (Columns a (Col (Reify context))))
-> AHMaybe context a
-> HMaybeTable (Columns a) (Col context)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    SContext context
-> (a -> Columns a (Col (Reify context)))
-> AHMaybe context a
-> AHMaybe context (Columns a (Col (Reify context)))
forall (context :: Context) a b.
SContext context
-> (a -> b) -> AHMaybe context a -> AHMaybe context b
smapMaybe SContext context
context (Columns a (Col (Reify (Reify context)))
-> Columns a (Col (Reify context))
forall (t :: HTable) (context :: Context).
HTable t =>
t (Col (Reify context)) -> t (Col context)
hunreify (Columns a (Col (Reify (Reify context)))
 -> Columns a (Col (Reify context)))
-> (a -> Columns a (Col (Reify (Reify context))))
-> a
-> Columns a (Col (Reify context))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Columns a (Col (Reify (Reify context)))
forall (context :: Context) a.
Table context a =>
a -> Columns a (Col context)
toColumns) (AHMaybe context a
 -> AHMaybe context (Columns a (Col (Reify context))))
-> (AHMaybe context a -> AHMaybe context a)
-> AHMaybe context a
-> AHMaybe context (Columns a (Col (Reify context)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    (\(AHMaybe HMaybe context a
a) -> AHMaybe context a
HMaybe context a
a)