on 28aaa76 help sign in
rel8/src/Rel8/Table/Alternative.hs
37 lines 1.1 kB history raw
1{-# language FlexibleContexts #-}
2{-# language StandaloneKindSignatures #-}
3{-# language TypeFamilies #-}
5module Rel8.Table.Alternative
6 ( AltTable ( (<|>:) )
7 , AlternativeTable ( emptyTable )
8 )
9where
11-- base
12import Data.Kind ( Constraint, Type )
13import Prelude ()
15-- rel8
16import Rel8.Expr ( Expr )
17import Rel8.Table ( Table )
20-- | Like 'Alt' in Haskell. This class is purely a Rel8 concept, and allows you
21-- to take a choice between two tables. See also 'AlternativeTable'.
22--
23-- For example, using '<|>:' on 'MaybeTable' allows you to combine two tables
24-- and to return the first one that is a "just" MaybeTable.
25type AltTable :: (Type -> Type) -> Constraint
26class AltTable f where
27 -- | An associative binary operation on 'Table's.
28 (<|>:) :: Table Expr a => f a -> f a -> f a
29 infixl 3 <|>:
32-- | Like 'Alternative' in Haskell, some 'Table's form a monoid on applicative
33-- functors.
34type AlternativeTable :: (Type -> Type) -> Constraint
35class AltTable f => AlternativeTable f where
36 -- | The identity of '<|>:'.
37 emptyTable :: Table Expr a => f a