[Haskell-cafe] more on the "Beautiful Concurrency" function
"withdraw" application ...
Galchin Vasili
vigalchin at gmail.com
Mon Dec 24 01:19:43 EST 2007
module Main where
import Control.Concurrent.STM
import Control.Concurrent
import System.Random
type Account = TVar Int
transfer :: Account -> Account -> Int -> IO ()
transfer from to amount
= atomically (do {deposit to amount;
withdraw from amount})
deposit :: Account -> Int -> STM ()
deposit acc amount = withdraw acc (- amount)
withdraw :: Account -> Int -> STM ()
withdraw acc amount
= do { bal <- readTVar acc;
writeTVar acc (bal - amount) }
When I try
withdraw (TVar 10) ..
I get "Not in scope: data constructor 'TVar'. OK .. "Tvar" is a class and
not a Haskell data type ... so now what?
Vasya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071224/586820cc/attachment.htm
More information about the Haskell-Cafe
mailing list