Guest User

Untitled

a guest
Jul 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. import System.IO
  2. import Control.Concurrent
  3. import Control.Concurrent.STM
  4.  
  5. type Account = TVar Int
  6.  
  7. transfer :: Account -> Account -> Int -> IO ()
  8. transfer from to amount
  9. = atomically (do deposit to amount
  10. withdraw from amount)
  11.  
  12. withdraw :: Account -> Int -> STM ()
  13. withdraw acc amount
  14. = do bal <- readTVar acc
  15. writeTVar acc (bal - amount)
  16.  
  17. deposit :: Account -> Int -> STM ()
  18. deposit acc amount = withdraw acc (- amount)
Add Comment
Please, Sign In to add comment