@@ -27,43 +27,10 @@ module Control.Monad.Class.MonadSTM
27
27
, LazyTMVar
28
28
-- * Default 'TMVar' implementation
29
29
, TMVarDefault (.. )
30
- , labelTMVarDefault
31
- , traceTMVarDefault
32
- , newTMVarDefault
33
- , newTMVarIODefault
34
- , newEmptyTMVarDefault
35
- , newEmptyTMVarIODefault
36
- , takeTMVarDefault
37
- , tryTakeTMVarDefault
38
- , putTMVarDefault
39
- , tryPutTMVarDefault
40
- , readTMVarDefault
41
- , tryReadTMVarDefault
42
- , swapTMVarDefault
43
- , isEmptyTMVarDefault
44
30
-- * Default 'TBQueue' implementation
45
31
, TQueueDefault (.. )
46
- , labelTQueueDefault
47
- , newTQueueDefault
48
- , readTQueueDefault
49
- , tryReadTQueueDefault
50
- , peekTQueueDefault
51
- , tryPeekTQueueDefault
52
- , writeTQueueDefault
53
- , isEmptyTQueueDefault
54
32
-- * Default 'TBQueue' implementation
55
33
, TBQueueDefault (.. )
56
- , labelTBQueueDefault
57
- , newTBQueueDefault
58
- , readTBQueueDefault
59
- , tryReadTBQueueDefault
60
- , peekTBQueueDefault
61
- , tryPeekTBQueueDefault
62
- , writeTBQueueDefault
63
- , isEmptyTBQueueDefault
64
- , isFullTBQueueDefault
65
- , lengthTBQueueDefault
66
- , flushTBQueueDefault
67
34
-- * MonadThrow aliases
68
35
, throwSTM
69
36
, catchSTM
@@ -73,7 +40,7 @@ module Control.Monad.Class.MonadSTM
73
40
, newTMVarMDefault
74
41
, newEmptyTMVarM
75
42
, newEmptyTMVarMDefault
76
- --
43
+ -- * Utils
77
44
, WrappedSTM (.. )
78
45
) where
79
46
@@ -188,13 +155,123 @@ class ( Monad m
188
155
newTQueueIO :: m (TQueue m a )
189
156
newTBQueueIO :: Natural -> m (TBQueue m a )
190
157
158
+ --
159
+ -- default implementations
160
+ --
161
+
162
+ default newTMVar :: TMVar m ~ TMVarDefault m
163
+ => a -> STM m (TMVar m a)
164
+ newTMVar = newTMVarDefault
165
+
166
+ default newEmptyTMVar :: TMVar m ~ TMVarDefault m
167
+ => STM m (TMVar m a)
168
+ newEmptyTMVar = newEmptyTMVarDefault
169
+
191
170
newTVarIO = atomically . newTVar
192
171
readTVarIO = atomically . readTVar
193
172
newTMVarIO = atomically . newTMVar
194
173
newEmptyTMVarIO = atomically newEmptyTMVar
195
174
newTQueueIO = atomically newTQueue
196
175
newTBQueueIO = atomically . newTBQueue
197
176
177
+ default takeTMVar :: TMVar m ~ TMVarDefault m
178
+ => TMVar m a -> STM m a
179
+ takeTMVar = takeTMVarDefault
180
+
181
+ default tryTakeTMVar :: TMVar m ~ TMVarDefault m
182
+ => TMVar m a -> STM m (Maybe a)
183
+ tryTakeTMVar = tryTakeTMVarDefault
184
+
185
+ default putTMVar :: TMVar m ~ TMVarDefault m => TMVar m a -> a -> STM m ()
186
+ putTMVar = putTMVarDefault
187
+
188
+ default tryPutTMVar :: TMVar m ~ TMVarDefault m => TMVar m a -> a -> STM m Bool
189
+ tryPutTMVar = tryPutTMVarDefault
190
+
191
+ default readTMVar :: TMVar m ~ TMVarDefault m
192
+ => TMVar m a -> STM m a
193
+ readTMVar = readTMVarDefault
194
+
195
+ default tryReadTMVar :: TMVar m ~ TMVarDefault m
196
+ => TMVar m a -> STM m (Maybe a)
197
+ tryReadTMVar = tryReadTMVarDefault
198
+
199
+ default swapTMVar :: TMVar m ~ TMVarDefault m
200
+ => TMVar m a -> a -> STM m a
201
+ swapTMVar = swapTMVarDefault
202
+
203
+ default isEmptyTMVar :: TMVar m ~ TMVarDefault m
204
+ => TMVar m a -> STM m Bool
205
+ isEmptyTMVar = isEmptyTMVarDefault
206
+
207
+ default newTQueue :: TQueue m ~ TQueueDefault m
208
+ => STM m (TQueue m a)
209
+ newTQueue = newTQueueDefault
210
+
211
+ default writeTQueue :: TQueue m ~ TQueueDefault m
212
+ => TQueue m a -> a -> STM m ()
213
+ writeTQueue = writeTQueueDefault
214
+
215
+ default readTQueue :: TQueue m ~ TQueueDefault m
216
+ => TQueue m a -> STM m a
217
+ readTQueue = readTQueueDefault
218
+
219
+ default tryReadTQueue :: TQueue m ~ TQueueDefault m
220
+ => TQueue m a -> STM m (Maybe a)
221
+ tryReadTQueue = tryReadTQueueDefault
222
+
223
+ default isEmptyTQueue :: TQueue m ~ TQueueDefault m
224
+ => TQueue m a -> STM m Bool
225
+ isEmptyTQueue = isEmptyTQueueDefault
226
+
227
+ default peekTQueue :: TQueue m ~ TQueueDefault m
228
+ => TQueue m a -> STM m a
229
+ peekTQueue = peekTQueueDefault
230
+
231
+ default tryPeekTQueue :: TQueue m ~ TQueueDefault m
232
+ => TQueue m a -> STM m (Maybe a)
233
+ tryPeekTQueue = tryPeekTQueueDefault
234
+
235
+ default newTBQueue :: TBQueue m ~ TBQueueDefault m
236
+ => Natural -> STM m (TBQueue m a)
237
+ newTBQueue = newTBQueueDefault
238
+
239
+ default writeTBQueue :: TBQueue m ~ TBQueueDefault m
240
+ => TBQueue m a -> a -> STM m ()
241
+ writeTBQueue = writeTBQueueDefault
242
+
243
+ default readTBQueue :: TBQueue m ~ TBQueueDefault m
244
+ => TBQueue m a -> STM m a
245
+ readTBQueue = readTBQueueDefault
246
+
247
+ default tryReadTBQueue :: TBQueue m ~ TBQueueDefault m
248
+ => TBQueue m a -> STM m (Maybe a)
249
+ tryReadTBQueue = tryReadTBQueueDefault
250
+
251
+ default isEmptyTBQueue :: TBQueue m ~ TBQueueDefault m
252
+ => TBQueue m a -> STM m Bool
253
+ isEmptyTBQueue = isEmptyTBQueueDefault
254
+
255
+ default peekTBQueue :: TBQueue m ~ TBQueueDefault m
256
+ => TBQueue m a -> STM m a
257
+ peekTBQueue = peekTBQueueDefault
258
+
259
+ default tryPeekTBQueue :: TBQueue m ~ TBQueueDefault m
260
+ => TBQueue m a -> STM m (Maybe a)
261
+ tryPeekTBQueue = tryPeekTBQueueDefault
262
+
263
+ default isFullTBQueue :: TBQueue m ~ TBQueueDefault m
264
+ => TBQueue m a -> STM m Bool
265
+ isFullTBQueue = isFullTBQueueDefault
266
+
267
+ default lengthTBQueue :: TBQueue m ~ TBQueueDefault m
268
+ => TBQueue m a -> STM m Natural
269
+ lengthTBQueue = lengthTBQueueDefault
270
+
271
+ default flushTBQueue :: TBQueue m ~ TBQueueDefault m
272
+ => TBQueue m a -> STM m [a]
273
+ flushTBQueue = flushTBQueueDefault
274
+
198
275
199
276
stateTVarDefault :: MonadSTM m => TVar m s -> (s -> (a , s )) -> STM m a
200
277
stateTVarDefault var f = do
@@ -237,6 +314,22 @@ class MonadSTM m
237
314
labelTQueueIO :: TQueue m a -> String -> m ()
238
315
labelTBQueueIO :: TBQueue m a -> String -> m ()
239
316
317
+ --
318
+ -- default implementations
319
+ --
320
+
321
+ default labelTMVar :: TMVar m ~ TMVarDefault m
322
+ => TMVar m a -> String -> STM m ()
323
+ labelTMVar = labelTMVarDefault
324
+
325
+ default labelTQueue :: TQueue m ~ TQueueDefault m
326
+ => TQueue m a -> String -> STM m ()
327
+ labelTQueue = labelTQueueDefault
328
+
329
+ default labelTBQueue :: TBQueue m ~ TBQueueDefault m
330
+ => TBQueue m a -> String -> STM m ()
331
+ labelTBQueue = labelTBQueueDefault
332
+
240
333
default labelTVarIO :: TVar m a -> String -> m ()
241
334
labelTVarIO = \ v l -> atomically (labelTVar v l)
242
335
@@ -524,6 +617,7 @@ newTMVarIODefault :: MonadSTM m => a -> m (TMVarDefault m a)
524
617
newTMVarIODefault a = do
525
618
t <- newTVarM (Just a)
526
619
return (TMVar t)
620
+ {-# DEPRECATED newTMVarIODefault "MonadSTM provides a default implementation" #-}
527
621
528
622
newTMVarMDefault :: MonadSTM m => a -> m (TMVarDefault m a )
529
623
newTMVarMDefault = newTMVarIODefault
@@ -538,6 +632,7 @@ newEmptyTMVarIODefault :: MonadSTM m => m (TMVarDefault m a)
538
632
newEmptyTMVarIODefault = do
539
633
t <- newTVarIO Nothing
540
634
return (TMVar t)
635
+ {-# DEPRECATED newEmptyTMVarIODefault "MonadSTM provides a default implementation" #-}
541
636
542
637
newEmptyTMVarMDefault :: MonadSTM m => m (TMVarDefault m a )
543
638
newEmptyTMVarMDefault = newEmptyTMVarIODefault
0 commit comments