1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language LambdaCase #-}
4{-# language MultiParamTypeClasses #-}
5{-# language StandaloneKindSignatures #-}
6{-# language TypeFamilies #-}
7{-# language UndecidableInstances #-}
9module Rel8.Column.Either
10 ( HEither, AHEither(..)
15import Control.Applicative ( liftA2 )
16import Data.Bifunctor ( Bifunctor, bimap )
17import Data.Kind ( Type )
21import Rel8.Aggregate ( Aggregate )
22import Rel8.Expr ( Expr )
23import Rel8.Kind.Context ( SContext(..), Reifiable( contextSing ) )
24import Rel8.Schema.Context ( Col )
25import Rel8.Schema.HTable.Either ( HEitherTable )
26import Rel8.Schema.Insert ( Insert )
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.Either ( EitherTable )
36import Rel8.Table.Recontextualize ( Recontextualize )
39type HEither :: K.Context -> Type -> Type -> Type
40type family HEither context where
41 HEither (Reify context) = AHEither context
42 HEither Aggregate = EitherTable
43 HEither Expr = EitherTable
44 HEither Insert = EitherTable
45 HEither Name = EitherTable
46 HEither Result = Either
49type AHEither :: K.Context -> Type -> Type -> Type
50newtype AHEither context a b = AHEither (HEither context a b)
53instance Reifiable context => Bifunctor (AHEither context) where
54 bimap = sbimapEither contextSing
57instance Reifiable context => Functor (AHEither context a) where
61instance (Reifiable context, Table (Reify context) a, Table (Reify context) b)
62 => Table (Reify context) (AHEither context a b)
64 type Context (AHEither context a b) = Reify context
65 type Columns (AHEither context a b) = HEitherTable (Columns a) (Columns b)
66 type Unreify (AHEither context a b) = HEither context (Unreify a) (Unreify b)
68 fromColumns = sfromColumnsEither contextSing
69 toColumns = stoColumnsEither contextSing
70 reify proof = liftA2 bimap reify reify proof . AHEither
71 unreify proof = (\(AHEither a) -> a) . liftA2 bimap unreify unreify proof
75 ( Reifiable context, Reifiable context'
76 , Recontextualize (Reify context) (Reify context') a a'
77 , Recontextualize (Reify context) (Reify context') b b'
82 (AHEither context a b)
83 (AHEither context' a' b')
90 -> AHEither context a b
91 -> AHEither context c d
93 SAggregate -> \f g (AHEither a) -> AHEither (bimap f g a)
94 SExpr -> \f g (AHEither a) -> AHEither (bimap f g a)
95 SResult -> \f g (AHEither a) -> AHEither (bimap f g a)
96 SInsert -> \f g (AHEither a) -> AHEither (bimap f g a)
97 SName -> \f g (AHEither a) -> AHEither (bimap f g a)
98 SReify context -> \f g (AHEither a) -> AHEither (sbimapEither context f g a)
101sfromColumnsEither :: (Table (Reify context) a, Table (Reify context) b)
103 -> HEitherTable (Columns a) (Columns b) (Col (Reify context))
104 -> AHEither context a b
105sfromColumnsEither = \case
108 bimap (fromColumns . hreify) (fromColumns . hreify) .
113 bimap (fromColumns . hreify) (fromColumns . hreify) .
118 bimap (fromColumns . hreify) (fromColumns . hreify) .
123 bimap (fromColumns . hreify) (fromColumns . hreify) .
128 bimap (fromColumns . hreify) (fromColumns . hreify) .
133 sbimapEither context (fromColumns . hreify) (fromColumns . hreify) .
134 sfromColumnsEither context .
138stoColumnsEither :: (Table (Reify context) a, Table (Reify context) b)
140 -> AHEither context a b
141 -> HEitherTable (Columns a) (Columns b) (Col (Reify context))
142stoColumnsEither = \case
146 bimap (hunreify . toColumns) (hunreify . toColumns) .
151 bimap (hunreify . toColumns) (hunreify . toColumns) .
156 bimap (hunreify . toColumns) (hunreify . toColumns) .
161 bimap (hunreify . toColumns) (hunreify . toColumns) .
166 bimap (hunreify . toColumns) (hunreify . toColumns) .
170 stoColumnsEither context .
171 sbimapEither 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