Skip to content

Commit aa22af7

Browse files
committed
Aggregate constraints for the unified class
1 parent abc1ee7 commit aa22af7

File tree

3 files changed

+29
-81
lines changed

3 files changed

+29
-81
lines changed

test/Database/LSMTree/Class.hs

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ class (IsSession (Session h)) => IsTable h where
4949

5050
lookups ::
5151
( IOLike m
52-
, SerialiseKey k
53-
, SerialiseValue v
54-
, ResolveValue v
5552
, C k v b
5653
)
5754
=> h m k v b
@@ -60,9 +57,6 @@ class (IsSession (Session h)) => IsTable h where
6057

6158
rangeLookup ::
6259
( IOLike m
63-
, SerialiseKey k
64-
, SerialiseValue v
65-
, ResolveValue v
6660
, C k v b
6761
)
6862
=> h m k v b
@@ -71,7 +65,6 @@ class (IsSession (Session h)) => IsTable h where
7165

7266
newCursor ::
7367
( IOLike m
74-
, SerialiseKey k
7568
, C k v b
7669
)
7770
=> Maybe k
@@ -88,9 +81,6 @@ class (IsSession (Session h)) => IsTable h where
8881

8982
readCursor ::
9083
( IOLike m
91-
, SerialiseKey k
92-
, SerialiseValue v
93-
, ResolveValue v
9484
, C k v b
9585
)
9686
=> proxy h
@@ -100,8 +90,7 @@ class (IsSession (Session h)) => IsTable h where
10090

10191
retrieveBlobs ::
10292
( IOLike m
103-
, SerialiseValue b
104-
, C_ b
93+
, CB b
10594
)
10695
=> proxy h
10796
-> Session h m
@@ -110,10 +99,6 @@ class (IsSession (Session h)) => IsTable h where
11099

111100
updates ::
112101
( IOLike m
113-
, SerialiseKey k
114-
, SerialiseValue v
115-
, SerialiseValue b
116-
, ResolveValue v
117102
, C k v b
118103
)
119104
=> h m k v b
@@ -122,10 +107,6 @@ class (IsSession (Session h)) => IsTable h where
122107

123108
inserts ::
124109
( IOLike m
125-
, SerialiseKey k
126-
, SerialiseValue v
127-
, SerialiseValue b
128-
, ResolveValue v
129110
, C k v b
130111
)
131112
=> h m k v b
@@ -134,10 +115,6 @@ class (IsSession (Session h)) => IsTable h where
134115

135116
deletes ::
136117
( IOLike m
137-
, SerialiseKey k
138-
, SerialiseValue v
139-
, SerialiseValue b
140-
, ResolveValue v
141118
, C k v b
142119
)
143120
=> h m k v b
@@ -146,10 +123,6 @@ class (IsSession (Session h)) => IsTable h where
146123

147124
mupserts ::
148125
( IOLike m
149-
, SerialiseKey k
150-
, SerialiseValue v
151-
, SerialiseValue b
152-
, ResolveValue v
153126
, C k v b
154127
)
155128
=> h m k v b
@@ -158,10 +131,6 @@ class (IsSession (Session h)) => IsTable h where
158131

159132
createSnapshot ::
160133
( IOLike m
161-
, SerialiseKey k
162-
, SerialiseValue v
163-
, SerialiseValue b
164-
, ResolveValue v
165134
, C k v b
166135
)
167136
=> SnapshotLabel
@@ -171,10 +140,6 @@ class (IsSession (Session h)) => IsTable h where
171140

172141
openSnapshot ::
173142
( IOLike m
174-
, SerialiseKey k
175-
, SerialiseValue v
176-
, ResolveValue v
177-
, SerialiseValue b
178143
, C k v b
179144
)
180145
=> Session h m
@@ -191,30 +156,22 @@ class (IsSession (Session h)) => IsTable h where
191156

192157
union ::
193158
( IOLike m
194-
, ResolveValue v
195-
, SerialiseValue v
196159
, C k v b
197160
)
198161
=> h m k v b
199162
-> h m k v b
200163
-> m (h m k v b)
201164

202165
withTableNew :: forall h m k v b a.
203-
( IOLike m
204-
, IsTable h
205-
, C k v b
206-
)
166+
(IOLike m, IsTable h, C k v b)
207167
=> Session h m
208168
-> TableConfig h
209169
-> (h m k v b -> m a)
210170
-> m a
211171
withTableNew sesh conf = bracket (new sesh conf) close
212172

213173
withTableFromSnapshot :: forall h m k v b a.
214-
( IOLike m, IsTable h
215-
, SerialiseKey k, SerialiseValue v, SerialiseValue b, ResolveValue v
216-
, C k v b
217-
)
174+
(IOLike m, IsTable h, C k v b)
218175
=> Session h m
219176
-> SnapshotLabel
220177
-> SnapshotName
@@ -223,34 +180,22 @@ withTableFromSnapshot :: forall h m k v b a.
223180
withTableFromSnapshot sesh label snap = bracket (openSnapshot sesh label snap) close
224181

225182
withTableDuplicate :: forall h m k v b a.
226-
( IOLike m
227-
, IsTable h
228-
, C k v b
229-
)
183+
(IOLike m, IsTable h, C k v b)
230184
=> h m k v b
231185
-> (h m k v b -> m a)
232186
-> m a
233187
withTableDuplicate table = bracket (duplicate table) close
234188

235189
withTableUnion :: forall h m k v b a.
236-
( IOLike m
237-
, IsTable h
238-
, SerialiseValue v
239-
, ResolveValue v
240-
, C k v b
241-
)
190+
(IOLike m, IsTable h, C k v b)
242191
=> h m k v b
243192
-> h m k v b
244193
-> (h m k v b -> m a)
245194
-> m a
246195
withTableUnion table1 table2 = bracket (table1 `union` table2) close
247196

248197
withCursor :: forall h m k v b a.
249-
( IOLike m
250-
, IsTable h
251-
, SerialiseKey k
252-
, C k v b
253-
)
198+
(IOLike m, IsTable h, C k v b)
254199
=> Maybe k
255200
-> h m k v b
256201
-> (Cursor h m k v b -> m a)

test/Database/LSMTree/Class/Common.hs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{-# LANGUAGE TypeFamilies #-}
22

33
module Database.LSMTree.Class.Common (
4-
C
5-
, C_
4+
C, CK, CV, CB, C_
65
, IsSession (..)
76
, SessionArgs (..)
87
, withSession
@@ -13,17 +12,37 @@ import Control.Monad.Class.MonadThrow (MonadThrow (..))
1312
import Control.Tracer (nullTracer)
1413
import Data.Kind (Constraint, Type)
1514
import Data.Typeable (Typeable)
15+
import Database.LSMTree (ResolveValue)
1616
import Database.LSMTree.Common as Types (IOLike, Range (..),
1717
SerialiseKey, SerialiseValue, SnapshotLabel (..),
1818
SnapshotName)
1919
import qualified Database.LSMTree.Common as R
2020
import System.FS.API (FsPath, HasFS)
2121
import System.FS.BlockIO.API (HasBlockIO)
2222

23-
-- | Model-specific constraints
24-
type C k v b = (C_ k, C_ v, C_ b)
23+
{-------------------------------------------------------------------------------
24+
Constraints
25+
-------------------------------------------------------------------------------}
26+
27+
-- | Constraints for keys, values, and blobs
28+
type C k v b = (CK k, CV v, CB b)
29+
30+
-- | Constaints for keys
31+
type CK k = (C_ k, SerialiseKey k)
32+
33+
-- | Constraints for values
34+
type CV v = (C_ v, SerialiseValue v, ResolveValue v)
35+
36+
-- | Constraints for blobs
37+
type CB b = (C_ b, SerialiseValue b)
38+
39+
-- | Model-specific constraints for keys, values, and blobs
2540
type C_ a = (Show a, Eq a, Typeable a)
2641

42+
{-------------------------------------------------------------------------------
43+
Session
44+
-------------------------------------------------------------------------------}
45+
2746
-- | Class abstracting over session operations.
2847
--
2948
type IsSession :: ((Type -> Type) -> Type) -> Constraint

test/Test/Database/LSMTree/Class.hs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ retrieveBlobsTrav hdl ses brefs = do
182182
lookupsWithBlobs :: forall h m k v b.
183183
( IsTable h
184184
, IOLike m
185-
, SerialiseKey k
186-
, SerialiseValue v
187-
, SerialiseValue b
188-
, ResolveValue v
189185
, C k v b
190186
)
191187
=> h m k v b
@@ -199,10 +195,6 @@ lookupsWithBlobs hdl ses ks = do
199195
rangeLookupWithBlobs :: forall h m k v b.
200196
( IsTable h
201197
, IOLike m
202-
, SerialiseKey k
203-
, SerialiseValue v
204-
, SerialiseValue b
205-
, ResolveValue v
206198
, C k v b
207199
)
208200
=> h m k v b
@@ -216,10 +208,6 @@ rangeLookupWithBlobs hdl ses r = do
216208
readCursorWithBlobs :: forall h m k v b proxy.
217209
( IsTable h
218210
, IOLike m
219-
, SerialiseKey k
220-
, SerialiseValue v
221-
, SerialiseValue b
222-
, ResolveValue v
223211
, C k v b
224212
)
225213
=> proxy h
@@ -234,10 +222,6 @@ readCursorWithBlobs hdl ses cursor n = do
234222
readCursorAllWithBlobs :: forall h m k v b proxy.
235223
( IsTable h
236224
, IOLike m
237-
, SerialiseKey k
238-
, SerialiseValue v
239-
, SerialiseValue b
240-
, ResolveValue v
241225
, C k v b
242226
)
243227
=> proxy h

0 commit comments

Comments
 (0)