1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language FlexibleInstances #-}
4{-# language MultiParamTypeClasses #-}
5{-# language NamedFieldPuns #-}
6{-# language ScopedTypeVariables #-}
7{-# language StandaloneKindSignatures #-}
8{-# language TypeApplications #-}
9{-# language TypeFamilies #-}
10{-# language UndecidableInstances #-}
14 , listTable, nameListTable
19import Data.Functor.Identity ( Identity( Identity ) )
20import Data.Kind ( Type )
21import Data.Type.Equality ( (:~:)( Refl ) )
25import Rel8.Expr ( Expr, Col( E, unE ) )
26import Rel8.Expr.Array ( sappend, sempty, slistOf )
27import Rel8.Schema.Dict ( Dict( Dict ) )
28import Rel8.Schema.HTable.List ( HListTable )
29import Rel8.Schema.HTable.Vectorize ( happend, hempty, hvectorize )
30import qualified Rel8.Schema.Kind as K
31import Rel8.Schema.Name ( Col( N ), Name( Name ) )
32import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
33import Rel8.Schema.Spec ( SSpec(..) )
34import Rel8.Schema.Reify ( hreify, hunreify )
36 ( Table, Context, Columns, fromColumns, toColumns
39import Rel8.Table.Alternative
41 , AlternativeTable, emptyTable
43import Rel8.Table.Eq ( EqTable, eqTable )
44import Rel8.Table.Ord ( OrdTable, ordTable )
45import Rel8.Table.Recontextualize ( Recontextualize )
46import Rel8.Table.Serialize ( FromExprs, ToExprs, fromResult, toResult )
47import Rel8.Table.Unreify ( Unreifies )
50-- | A @ListTable@ value contains zero or more instances of @a@. You construct
51-- @ListTable@s with 'Rel8.many' or 'Rel8.listAgg'.
52type ListTable :: K.Context -> Type -> Type
53newtype ListTable context a =
54 ListTable (HListTable (Columns a) (Col (Context a)))
57instance (Table context a, Unreifies context a, context ~ context') =>
58 Table context' (ListTable context a)
60 type Columns (ListTable context a) = HListTable (Columns a)
61 type Context (ListTable context a) = Context a
63 fromColumns = ListTable
64 toColumns (ListTable a) = a
66 reify Refl (ListTable a) = ListTable (hreify a)
67 unreify Refl (ListTable a) = ListTable (hunreify a)
71 ( Unreifies from a, from ~ from'
72 , Unreifies to b, to ~ to'
73 , Recontextualize from to a b
75 => Recontextualize from to (ListTable from' a) (ListTable to' b)
78instance (EqTable a, context ~ Expr) => EqTable (ListTable context a) where
81 (\SSpec {nullity} (Identity Dict) -> case nullity of
84 (Identity (eqTable @a))
87instance (OrdTable a, context ~ Expr) => OrdTable (ListTable context a) where
90 (\SSpec {nullity} (Identity Dict) -> case nullity of
93 (Identity (ordTable @a))
96type instance FromExprs (ListTable _context a) = [FromExprs a]
99instance (ToExprs exprs a, context ~ Expr) =>
100 ToExprs (ListTable context exprs) [a]
102 fromResult = fmap (fromResult @exprs) . fromColumns
103 toResult = toColumns . fmap (toResult @exprs)
106instance context ~ Expr => AltTable (ListTable context) where
110instance context ~ Expr => AlternativeTable (ListTable context) where
114instance (context ~ Expr, Table Expr a) =>
115 Semigroup (ListTable context a)
117 ListTable as <> ListTable bs = ListTable $
118 happend (\_ _ (E a) (E b) -> E (sappend a b)) as bs
121instance (context ~ Expr, Table Expr a) =>
122 Monoid (ListTable context a)
124 mempty = ListTable $ hempty $ \_ -> E . sempty
127-- | Construct a @ListTable@ from a list of expressions.
128listTable :: Table Expr a => [a] -> ListTable Expr a
131 hvectorize (\SSpec {info} -> E . slistOf info . fmap unE) .
135-- | Construct a 'ListTable' in the 'Name' context. This can be useful if you
136-- have a 'ListTable' that you are storing in a table and need to construct a
140 => a -- ^ The names of the columns of elements of the list.
144 hvectorize (\_ (Identity (N (Name a))) -> N (Name a)) .
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