A simple STM Example

Haskell package の STM の簡単な例

repl(ghci)で実行する。

:set +m
:set -package stm

import Control.Concurrent.STM

testFunc :: TVar Int -> STM Int
testFunc = readTVar

main :: IO ()
main = do
  ref <- newTVarIO (4 :: Int)
  (atomically $ testFunc ref) >>= \s -> putStrLn $ show s

main