on 2ba99ea help sign in
rel8/src/Rel8/Type/Monoid.hs
79 lines 1.8 kB history raw
1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language FlexibleInstances #-}
4{-# language MultiParamTypeClasses #-}
5{-# language OverloadedStrings #-}
6{-# language StandaloneKindSignatures #-}
7{-# language TypeFamilies #-}
8{-# language UndecidableInstances #-}
10module Rel8.Type.Monoid
11 ( DBMonoid( memptyExpr )
12 )
13where
15-- base
16import Data.Kind ( Constraint, Type )
17import Prelude hiding ( null )
19-- bytestring
20import Data.ByteString ( ByteString )
21import qualified Data.ByteString.Lazy as Lazy ( ByteString )
23-- case-insensitive
24import Data.CaseInsensitive ( CI )
26-- rel8
27import {-# SOURCE #-} Rel8.Expr ( Expr )
28import Rel8.Expr.Array ( sempty )
29import Rel8.Expr.Serialize ( litExpr )
30import Rel8.Schema.Null ( Sql )
31import Rel8.Type ( DBType, typeInformation )
32import Rel8.Type.Semigroup ( DBSemigroup )
34-- text
35import Data.Text ( Text )
36import qualified Data.Text.Lazy as Lazy ( Text )
38-- time
39import Data.Time.LocalTime ( CalendarDiffTime( CalendarDiffTime ) )
42-- | The class of 'Rel8.DBType's that form a semigroup. This class is purely a
43-- Rel8 concept, and exists to mirror the 'Monoid' class.
44type DBMonoid :: Type -> Constraint
45class DBSemigroup a => DBMonoid a where
46 -- The identity for '<>.'
47 memptyExpr :: Expr a
50instance Sql DBType a => DBMonoid [a] where
51 memptyExpr = sempty typeInformation
54instance DBMonoid CalendarDiffTime where
55 memptyExpr = litExpr (CalendarDiffTime 0 0)
58instance DBMonoid Text where
59 memptyExpr = litExpr ""
62instance DBMonoid Lazy.Text where
63 memptyExpr = litExpr ""
66instance DBMonoid (CI Text) where
67 memptyExpr = litExpr ""
70instance DBMonoid (CI Lazy.Text) where
71 memptyExpr = litExpr ""
74instance DBMonoid ByteString where
75 memptyExpr = litExpr ""
78instance DBMonoid Lazy.ByteString where
79 memptyExpr = litExpr ""