on 289d7ca help sign in
rel8/src/Rel8/Type/Monoid.hs
82 lines 1.8 kB history raw
1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language FlexibleInstances #-}
4{-# language OverloadedStrings #-}
5{-# language StandaloneKindSignatures #-}
6{-# language TypeFamilies #-}
7{-# language UndecidableInstances #-}
9module Rel8.Type.Monoid
10 ( DBMonoid( memptyExpr )
11 )
12where
14-- base
15import Data.Kind ( Constraint, Type )
16import Prelude hiding ( null )
18-- bytestring
19import Data.ByteString ( ByteString )
20import qualified Data.ByteString.Lazy as Lazy ( ByteString )
22-- case-insensitive
23import Data.CaseInsensitive ( CI )
25-- rel8
26import {-# SOURCE #-} Rel8.Expr ( Expr )
27import Rel8.Expr.Array ( sempty )
28import Rel8.Expr.Serialize ( litExpr )
29import Rel8.Schema.Nullability ( Sql, nullabilization )
30import Rel8.Type ( DBType, typeInformation )
31import Rel8.Type.Semigroup ( DBSemigroup )
33-- text
34import Data.Text ( Text )
35import qualified Data.Text.Lazy as Lazy ( Text )
37-- time
38import Data.Time.Clock ( DiffTime, NominalDiffTime )
41-- | The class of 'DBType's that form a semigroup. This class is purely a Rel8
42-- concept, and exists to mirror the 'Monoid' class.
43type DBMonoid :: Type -> Constraint
44class DBSemigroup a => DBMonoid a where
45 -- The identity for '<>.'
46 memptyExpr :: Expr a
49instance Sql DBType a => DBMonoid [a] where
50 memptyExpr = sempty nullabilization typeInformation
53instance DBMonoid DiffTime where
54 memptyExpr = litExpr 0
57instance DBMonoid NominalDiffTime where
58 memptyExpr = litExpr 0
61instance DBMonoid Text where
62 memptyExpr = litExpr ""
65instance DBMonoid Lazy.Text where
66 memptyExpr = litExpr ""
69instance DBMonoid (CI Text) where
70 memptyExpr = litExpr ""
73instance DBMonoid (CI Lazy.Text) where
74 memptyExpr = litExpr ""
77instance DBMonoid ByteString where
78 memptyExpr = litExpr ""
81instance DBMonoid Lazy.ByteString where
82 memptyExpr = litExpr ""