Skip to content

Commit 5f4d7c6

Browse files
lehinshvr
authored andcommitted
Typesafety improvements to TSem (gh-17)
* Switch to Natural in signalTSem * make newTSem accept Integer
1 parent f1ae7dc commit 5f4d7c6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Control/Concurrent/STM/TSem.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Control.Concurrent.STM.TSem
2727
import Control.Concurrent.STM
2828
import Control.Monad
2929
import Data.Typeable
30-
import Data.Word as Word
30+
import Numeric.Natural
3131

3232
-- | 'TSem' is a transactional semaphore. It holds a certain number
3333
-- of units, and units may be acquired or released by 'waitTSem' and
@@ -56,8 +56,8 @@ newtype TSem = TSem (TVar Integer)
5656
-- operations to counter-balance.
5757
--
5858
-- @since 2.4.2
59-
newTSem :: Int -> STM TSem
60-
newTSem i = fmap TSem (newTVar $! toInteger i)
59+
newTSem :: Integer -> STM TSem
60+
newTSem i = fmap TSem (newTVar $! i)
6161

6262
-- NOTE: we can't expose a good `TSem -> STM Int' operation as blocked
6363
-- 'waitTSem' aren't reliably reflected in a negative counter value.
@@ -99,7 +99,7 @@ signalTSem (TSem t) = do
9999
-- > signalTSem == signalTSemN 1
100100
--
101101
-- @since 2.4.5
102-
signalTSemN :: Word.Word -> TSem -> STM ()
102+
signalTSemN :: Natural -> TSem -> STM ()
103103
signalTSemN 0 _ = return ()
104104
signalTSemN 1 s = signalTSem s
105105
signalTSemN n (TSem t) = do

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
* Switched `newTBQueue` and `newTBQueueIO` to accept `Natural` as size (gh-17)
1010

11+
* Switched `signalTSemN` and `newTSem` to accept `Natural` and `Integer` respectively (gh-17)
12+
1113
----
1214

1315
#### 2.4.5.1 *Sep 2018*

0 commit comments

Comments
 (0)