Skip to content

Commit

Permalink
More strict newTVarWithInvariant, newTVarWithInvariantIO and newMVarW…
Browse files Browse the repository at this point in the history
…ithInvariant

Although the underlying mutable variable is strict, we execute the
invariant on the initial data, for this reason we have to evaluate it
before writing it to the variable.
  • Loading branch information
coot committed Aug 3, 2023
1 parent 4427205 commit 0e2f101
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions strict-checked-vars/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history of strict-checked-vars

## 0.1.0.2

* Make `newTVarWithInvariant`, `newTVarWithInvariantIO` and `newMVarWithInvariant` strict.

## 0.1.0.1

* Export `checkInvariant`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
Expand Down Expand Up @@ -99,7 +100,7 @@ newMVarWithInvariant :: (HasCallStack, MonadMVar m)
=> (a -> Maybe String)
-> a
-> m (StrictMVar m a)
newMVarWithInvariant inv a =
newMVarWithInvariant inv !a =
checkInvariant (inv a) $
StrictMVar inv <$> Strict.newMVar a

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

Expand Down Expand Up @@ -85,15 +86,15 @@ newTVarWithInvariant :: (MonadSTM m, HasCallStack)
=> (a -> Maybe String)
-> a
-> STM m (StrictTVar m a)
newTVarWithInvariant inv a =
newTVarWithInvariant inv !a =
checkInvariant (inv a) $
StrictTVar inv <$> Strict.newTVar a

newTVarWithInvariantIO :: (MonadSTM m, HasCallStack)
=> (a -> Maybe String)
-> a
-> m (StrictTVar m a)
newTVarWithInvariantIO inv a =
newTVarWithInvariantIO inv !a =
checkInvariant (inv a) $
StrictTVar inv <$> Strict.newTVarIO a

Expand Down
2 changes: 1 addition & 1 deletion strict-checked-vars/strict-checked-vars.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: strict-checked-vars
version: 0.1.0.1
version: 0.1.0.2
synopsis:
Strict MVars and TVars with invariant checking for IO and IOSim

Expand Down

0 comments on commit 0e2f101

Please sign in to comment.