Skip to content

Commit

Permalink
add a loop in the mutable-references example
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed Jul 27, 2019
1 parent cd31ad0 commit e845428
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions mutable-references.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Control.Monad.STM
import Control.Concurrent.STM.TVar

import Data.Foldable (for_)

main =
do
a <- atomically (newTVar 3)
Expand Down Expand Up @@ -34,8 +36,8 @@ main =
writeTVar ref2 x1

increment a
increment a
increment b
for_ [1..5] $ \_ ->
increment b
printVars "incremented"

swap a b
Expand Down
4 changes: 2 additions & 2 deletions outputs/mutable-references.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
a = 3, b = 5 (initial values)
a = 7, b = 5 (changed a to 7)
a = 7, b = 10 (doubled b)
a = 9, b = 11 (incremented)
a = 11, b = 9 (swapped)
a = 8, b = 15 (incremented)
a = 15, b = 8 (swapped)

0 comments on commit e845428

Please sign in to comment.