1{-# language AllowAmbiguousTypes #-}
2{-# language BlockArguments #-}
3{-# language DataKinds #-}
4{-# language DefaultSignatures #-}
5{-# language DisambiguateRecordFields #-}
6{-# language FlexibleContexts #-}
7{-# language FlexibleInstances #-}
8{-# language LambdaCase #-}
9{-# language NamedFieldPuns #-}
10{-# language ScopedTypeVariables #-}
11{-# language StandaloneKindSignatures #-}
12{-# language TypeApplications #-}
13{-# language TypeFamilies #-}
14{-# language UndecidableInstances #-}
15{-# language UndecidableSuperClasses #-}
16{-# language ViewPatterns #-}
19 ( EqTable( eqTable ), (==:), (/=:)
24import Data.Foldable ( foldl' )
25import Data.Functor.Const ( Const( Const ), getConst )
26import Data.Kind ( Constraint, Type )
27import Data.List.NonEmpty ( NonEmpty( (:|) ) )
31import Rel8.Expr ( Expr, Col(..) )
32import Rel8.Expr.Bool ( (||.), (&&.) )
33import Rel8.Expr.Eq ( (==.), (/=.) )
34import Rel8.Schema.Context.Label ( hlabeler )
35import Rel8.Schema.Dict ( Dict( Dict ) )
36import Rel8.Schema.HTable
37 ( HTable, HConstrainTable
38 , htabulateA, hfield, hdicts
40import Rel8.Schema.HTable.Label ( hlabel )
41import Rel8.Schema.HTable.Pair ( HPair(..) )
42import Rel8.Schema.HTable.Quartet ( HQuartet(..) )
43import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
44import Rel8.Schema.HTable.Trio ( HTrio(..) )
45import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
46import Rel8.Table ( Table, Columns, toColumns )
47import Rel8.Type.Eq ( DBEq )
48import Rel8.Schema.Nullability ( Sql )
51type EqTable :: Type -> Constraint
52class Table Expr a => EqTable a where
53 eqTable :: Columns a (Dict (ConstrainDBType DBEq))
56 => HConstrainTable (Columns a) (ConstrainDBType DBEq)
57 => Columns a (Dict (ConstrainDBType DBEq))
58 eqTable = hdicts @(Columns a) @(ConstrainDBType DBEq)
64 , HConstrainTable (Columns (t Expr)) (ConstrainDBType DBEq)
72 , HConstrainTable t (ConstrainDBType DBEq)
77instance Sql DBEq a => EqTable (Expr a)
80instance (EqTable a, EqTable b) => EqTable (a, b) where
83 { hfst = hlabel hlabeler (eqTable @a)
84 , hsnd = hlabel hlabeler (eqTable @b)
88instance (EqTable a, EqTable b, EqTable c) => EqTable (a, b, c) where
91 { hfst = hlabel hlabeler (eqTable @a)
92 , hsnd = hlabel hlabeler (eqTable @b)
93 , htrd = hlabel hlabeler (eqTable @c)
97instance (EqTable a, EqTable b, EqTable c, EqTable d) => EqTable (a, b, c, d)
101 { hfst = hlabel hlabeler (eqTable @a)
102 , hsnd = hlabel hlabeler (eqTable @b)
103 , htrd = hlabel hlabeler (eqTable @c)
104 , hfrt = hlabel hlabeler (eqTable @d)
108instance (EqTable a, EqTable b, EqTable c, EqTable d, EqTable e) =>
109 EqTable (a, b, c, d, e)
113 { hfst = hlabel hlabeler (eqTable @a)
114 , hsnd = hlabel hlabeler (eqTable @b)
115 , htrd = hlabel hlabeler (eqTable @c)
116 , hfrt = hlabel hlabeler (eqTable @d)
117 , hfft = hlabel hlabeler (eqTable @e)
121-- | Compare two 'Table's for equality. This corresponds to comparing all
122-- columns inside each table for equality, and combining all comparisons with
124(==:) :: forall a. EqTable a => a -> a -> Expr Bool
125(toColumns -> as) ==: (toColumns -> bs) =
126 foldl1' (&&.) $ getConst $ htabulateA $ \field ->
127 case (hfield as field, hfield bs field) of
128 (DB a, DB b) -> case hfield (eqTable @a) field of
129 Dict -> Const (pure (a ==. b))
133-- | Test if two 'Table's are different. This corresponds to comparing all
134-- columns inside each table for inequality, and combining all comparisons with
136(/=:) :: forall a. EqTable a => a -> a -> Expr Bool
137(toColumns -> as) /=: (toColumns -> bs) =
138 foldl1' (||.) $ getConst $ htabulateA $ \field ->
139 case (hfield as field, hfield bs field) of
140 (DB a, DB b) -> case hfield (eqTable @a) field of
141 Dict -> Const (pure (a /=. b))
145foldl1' :: (a -> a -> a) -> NonEmpty a -> a
146foldl1' f (a :| as) = foldl' f a as
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list