1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
4{-# language LambdaCase #-}
5{-# language MultiParamTypeClasses #-}
6{-# language StandaloneKindSignatures #-}
7{-# language TypeFamilies #-}
8{-# language UndecidableInstances #-}
10module Rel8.Column.These
16import Control.Applicative ( liftA2 )
17import Data.Bifunctor ( Bifunctor, bimap )
18import Data.Kind ( Type )
22import Rel8.Aggregate ( Aggregate )
23import Rel8.Expr ( Expr )
24import Rel8.Kind.Context ( SContext(..), Reifiable( contextSing ) )
25import Rel8.Schema.Context ( Col )
26import Rel8.Schema.HTable.These ( HTheseTable )
27import qualified Rel8.Schema.Kind as K
28import Rel8.Schema.Name ( Name )
29import Rel8.Schema.Reify ( Reify, hreify, hunreify )
30import Rel8.Schema.Result ( Result )
32 ( Table, Columns, Context, fromColumns, toColumns
33 , Unreify, reify, unreify
35import Rel8.Table.Recontextualize ( Recontextualize )
36import Rel8.Table.These ( TheseTable )
39import Data.These ( These )
42-- | Nest an 'These' value within a 'Rel8able'. @HThese f a b@ will produce a
43-- 'TheseTable' @a b@ in the 'Expr' context, and a 'These' @a b@ in the
45type HThese :: K.Context -> Type -> Type -> Type
46type family HThese context where
47 HThese (Reify context) = AHThese context
48 HThese Aggregate = TheseTable
49 HThese Expr = TheseTable
50 HThese Name = TheseTable
54type AHThese :: K.Context -> Type -> Type -> Type
55newtype AHThese context a b = AHThese (HThese context a b)
58instance Reifiable context => Bifunctor (AHThese context) where
59 bimap = sbimapThese contextSing
62instance Reifiable context => Functor (AHThese context a) where
66instance (Reifiable context, Table (Reify context) a, Table (Reify context) b)
67 => Table (Reify context) (AHThese context a b)
69 type Context (AHThese context a b) = Reify context
70 type Columns (AHThese context a b) = HTheseTable (Columns a) (Columns b)
71 type Unreify (AHThese context a b) = HThese context (Unreify a) (Unreify b)
73 fromColumns = sfromColumnsThese contextSing
74 toColumns = stoColumnsThese contextSing
75 reify proof = liftA2 bimap reify reify proof . AHThese
76 unreify proof = (\(AHThese a) -> a) . liftA2 bimap unreify unreify proof
80 ( Reifiable context, Reifiable context'
81 , Recontextualize (Reify context) (Reify context') a a'
82 , Recontextualize (Reify context) (Reify context') b b'
88 (AHThese context' a' b')
95 -> AHThese context a b
96 -> AHThese context c d
98 SAggregate -> \f g (AHThese a) -> AHThese (bimap f g a)
99 SExpr -> \f g (AHThese a) -> AHThese (bimap f g a)
100 SResult -> \f g (AHThese a) -> AHThese (bimap f g a)
101 SName -> \f g (AHThese a) -> AHThese (bimap f g a)
102 SReify context -> \f g (AHThese a) -> AHThese (sbimapThese context f g a)
105sfromColumnsThese :: (Table (Reify context) a, Table (Reify context) b)
107 -> HTheseTable (Columns a) (Columns b) (Col (Reify context))
108 -> AHThese context a b
109sfromColumnsThese = \case
112 bimap (fromColumns . hreify) (fromColumns . hreify) .
117 bimap (fromColumns . hreify) (fromColumns . hreify) .
122 bimap (fromColumns . hreify) (fromColumns . hreify) .
127 bimap (fromColumns . hreify) (fromColumns . hreify) .
132 sbimapThese context (fromColumns . hreify) (fromColumns . hreify) .
133 sfromColumnsThese context .
137stoColumnsThese :: (Table (Reify context) a, Table (Reify context) b)
139 -> AHThese context a b
140 -> HTheseTable (Columns a) (Columns b) (Col (Reify context))
141stoColumnsThese = \case
145 bimap (hunreify . toColumns) (hunreify . toColumns) .
150 bimap (hunreify . toColumns) (hunreify . toColumns) .
155 bimap (hunreify . toColumns) (hunreify . toColumns) .
160 bimap (hunreify . toColumns) (hunreify . toColumns) .
164 stoColumnsThese context .
165 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