on 00a36f5 help sign in
rel8/src/Rel8/Table/List.hs
64 lines 1.7 kB history raw
1{-# language FlexibleContexts #-}
2{-# language FlexibleInstances #-}
3{-# language MultiParamTypeClasses #-}
4{-# language StandaloneKindSignatures #-}
5{-# language TypeFamilies #-}
6{-# language UndecidableInstances #-}
8module Rel8.Table.List
9 ( ListTable(..)
10 )
11where
13-- base
14import Data.Kind ( Type )
15import Prelude
17-- rel8
18import Rel8.Expr ( Expr )
19import Rel8.Expr.Array ( sappend, sempty )
20import Rel8.Schema.Context ( Col, Col'(..) )
21import Rel8.Schema.HTable.List ( HListTable )
22import Rel8.Schema.HTable.Vectorize ( happend, hempty )
23import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
24import Rel8.Table.Alternative
25 ( AltTable, (<|>:)
26 , AlternativeTable, emptyTable
27 )
28import Rel8.Table.Recontextualize ( Recontextualize )
31-- | A @ListTable@ value contains zero or more instances of @a@. You construct
32-- @ListTable@s with 'many' or 'listAgg'.
33type ListTable :: Type -> Type
34newtype ListTable a = ListTable (HListTable (Columns a) (Col (Context a)))
37instance Table context a => Table context (ListTable a) where
38 type Columns (ListTable a) = HListTable (Columns a)
39 type Context (ListTable a) = Context a
41 fromColumns = ListTable
42 toColumns (ListTable a) = a
45instance Recontextualize from to a b =>
46 Recontextualize from to (ListTable a) (ListTable b)
49instance AltTable ListTable where
50 (<|>:) = (<>)
53instance AlternativeTable ListTable where
54 emptyTable = mempty
57instance Table Expr a => Semigroup (ListTable a) where
58 ListTable as <> ListTable bs = ListTable $
59 happend (\_ _ (DB a) (DB b) -> DB (sappend a b)) as bs
62instance Table Expr a => Monoid (ListTable a) where
63 mempty = ListTable $ hempty $ \nullability info ->
64 DB (sempty nullability info)