1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
4{-# language LambdaCase #-}
5{-# language MultiParamTypeClasses #-}
6{-# language ScopedTypeVariables #-}
7{-# language StandaloneKindSignatures #-}
8{-# language TypeApplications #-}
9{-# language TypeFamilyDependencies #-}
10{-# language UndecidableInstances #-}
12module Rel8.Column.These
18import Control.Applicative ( liftA2 )
19import Control.Category ( id )
20import Data.Bifunctor ( Bifunctor, bimap )
21import Data.Kind ( Type )
22import Data.Type.Equality ( (:~:)( Refl ), apply )
23import Prelude hiding ( id )
26import Rel8.Aggregate ( Aggregate )
27import Rel8.Expr ( Expr )
28import Rel8.Kind.Context ( SContext(..), Reifiable( contextSing ) )
29import Rel8.Schema.Context ( Col )
30import Rel8.Schema.HTable.These ( HTheseTable )
31import qualified Rel8.Schema.Kind as K
32import Rel8.Schema.Name ( Name )
33import Rel8.Schema.Reify ( Reify, hreify, hunreify )
34import Rel8.Schema.Result ( Result, absurd )
36 ( Table, Columns, Context, fromColumns, toColumns
37 , Unreify, reify, unreify, coherence, congruence
39import Rel8.Table.Recontextualize ( Recontextualize )
40import Rel8.Table.These ( TheseTable )
43import Data.These ( These )
46-- | Nest an 'These' value within a 'Rel8able'. @HThese f a b@ will produce a
47-- 'TheseTable' @a b@ in the 'Expr' context, and a 'These' @a b@ in the
49type HThese :: K.Context -> Type -> Type -> Type
50type family HThese context = these | these -> context where
51 HThese (Reify context) = AHThese context
52 HThese Aggregate = TheseTable Aggregate
53 HThese Expr = TheseTable Expr
54 HThese Name = TheseTable Name
58type AHThese :: K.Context -> Type -> Type -> Type
59newtype AHThese context a b = AHThese (HThese context a b)
62instance Reifiable context => Bifunctor (AHThese context) where
63 bimap = sbimapThese contextSing
66instance Reifiable context => Functor (AHThese context a) where
70instance (Reifiable context, Table (Reify context) a, Table (Reify context) b)
71 => Table (Reify context) (AHThese context a b)
73 type Context (AHThese context a b) = Reify context
74 type Columns (AHThese context a b) = HTheseTable (Columns a) (Columns b)
75 type Unreify (AHThese context a b) = HThese context (Unreify a) (Unreify b)
77 fromColumns = sfromColumnsThese contextSing
78 toColumns = stoColumnsThese contextSing
79 reify proof = liftA2 bimap reify reify proof . AHThese
80 unreify proof = (\(AHThese a) -> a) . liftA2 bimap unreify unreify proof
82 coherence = case contextSing @context of
83 SAggregate -> coherence @(Reify context) @a
84 SExpr -> coherence @(Reify context) @a
85 SName -> coherence @(Reify context) @a
86 SResult -> \Refl -> absurd
87 SReify _ -> \Refl _ -> Refl
89 congruence proof@Refl abstract = case contextSing @context of
92 congruence @(Reify context) @a proof abstract `apply`
93 congruence @(Reify context) @b proof abstract
96 congruence @(Reify context) @a proof abstract `apply`
97 congruence @(Reify context) @b proof abstract
100 congruence @(Reify context) @a proof abstract `apply`
101 congruence @(Reify context) @b proof abstract
102 SResult -> absurd abstract
105 congruence @(Reify context) @a proof abstract `apply`
106 congruence @(Reify context) @b proof abstract
110 ( Reifiable context, Reifiable context'
111 , Recontextualize (Reify context) (Reify context') a a'
112 , Recontextualize (Reify context) (Reify context') b b'
117 (AHThese context a b)
118 (AHThese context' a' b')
125 -> AHThese context a b
126 -> AHThese context c d
128 SAggregate -> \f g (AHThese a) -> AHThese (bimap f g a)
129 SExpr -> \f g (AHThese a) -> AHThese (bimap f g a)
130 SResult -> \f g (AHThese a) -> AHThese (bimap f g a)
131 SName -> \f g (AHThese a) -> AHThese (bimap f g a)
132 SReify context -> \f g (AHThese a) -> AHThese (sbimapThese context f g a)
135sfromColumnsThese :: (Table (Reify context) a, Table (Reify context) b)
137 -> HTheseTable (Columns a) (Columns b) (Col (Reify context))
138 -> AHThese context a b
139sfromColumnsThese = \case
142 bimap (fromColumns . hreify) (fromColumns . hreify) .
147 bimap (fromColumns . hreify) (fromColumns . hreify) .
152 bimap (fromColumns . hreify) (fromColumns . hreify) .
157 bimap (fromColumns . hreify) (fromColumns . hreify) .
162 sbimapThese context (fromColumns . hreify) (fromColumns . hreify) .
163 sfromColumnsThese context .
167stoColumnsThese :: (Table (Reify context) a, Table (Reify context) b)
169 -> AHThese context a b
170 -> HTheseTable (Columns a) (Columns b) (Col (Reify context))
171stoColumnsThese = \case
175 bimap (hunreify . toColumns) (hunreify . toColumns) .
180 bimap (hunreify . toColumns) (hunreify . toColumns) .
185 bimap (hunreify . toColumns) (hunreify . toColumns) .
190 bimap (hunreify . toColumns) (hunreify . toColumns) .
194 stoColumnsThese context .
195 sbimapThese context (hunreify . toColumns) (hunreify . 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