on 00a36f5 help sign in
rel8/src/Rel8/Table/NonEmpty.hs
53 lines 1.5 kB history raw
1{-# language FlexibleInstances #-}
2{-# language MultiParamTypeClasses #-}
3{-# language StandaloneKindSignatures #-}
4{-# language TypeFamilies #-}
5{-# language UndecidableInstances #-}
7module Rel8.Table.NonEmpty
8 ( NonEmptyTable(..)
9 , HNonEmptyTable
10 )
11where
13-- base
14import Data.Kind ( Type )
15import Prelude
17-- rel8
18import Rel8.Expr ( Expr )
19import Rel8.Expr.Array ( sappend1 )
20import Rel8.Schema.Context ( Col, Col'(..) )
21import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
22import Rel8.Schema.HTable.Vectorize ( happend )
23import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
24import Rel8.Table.Alternative ( AltTable, (<|>:) )
25import Rel8.Table.Recontextualize ( Recontextualize )
28-- | A @NonEmptyTable@ value contains one or more instances of @a@. You
29-- construct @NonEmptyTable@s with 'some' or 'nonEmptyAgg'.
30type NonEmptyTable :: Type -> Type
31newtype NonEmptyTable a =
32 NonEmptyTable (HNonEmptyTable (Columns a) (Col (Context a)))
35instance Table context a => Table context (NonEmptyTable a) where
36 type Columns (NonEmptyTable a) = HNonEmptyTable (Columns a)
37 type Context (NonEmptyTable a) = Context a
39 fromColumns = NonEmptyTable
40 toColumns (NonEmptyTable a) = a
43instance Recontextualize from to a b =>
44 Recontextualize from to (NonEmptyTable a) (NonEmptyTable b)
47instance AltTable NonEmptyTable where
48 (<|>:) = (<>)
51instance Table Expr a => Semigroup (NonEmptyTable a) where
52 NonEmptyTable as <> NonEmptyTable bs = NonEmptyTable $
53 happend (\_ _ (DB a) (DB b) -> DB (sappend1 a b)) as bs