Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System.IO
- import Control.Concurrent
- import Control.Concurrent.STM
- type Account = TVar Int
- transfer :: Account -> Account -> Int -> IO ()
- transfer from to amount
- = atomically (do deposit to amount
- withdraw from amount)
- withdraw :: Account -> Int -> STM ()
- withdraw acc amount
- = do bal <- readTVar acc
- writeTVar acc (bal - amount)
- deposit :: Account -> Int -> STM ()
- deposit acc amount = withdraw acc (- amount)
Add Comment
Please, Sign In to add comment