-newQSemN :: Int -> IO QSemN
-newQSemN initial = do
- sem <- newMVar (initial, [])
- return (QSemN sem)
+-- The initial quantity must be at least 0.
+newQSemN :: Int -> IO QSemN
+newQSemN initial =
+ if initial < 0
+ then fail "newQSemN: Initial quantity must be non-negative"
+ else do sem <- newMVar (initial, [])
+ return (QSemN sem)