<div>{- compile with ghc --make stm.hs -}</div>
<div>module Main where<br>import Control.Concurrent.STM</div>
<div> </div>
<div>type Account = TVar Int</div>
<div> </div>
<div>withdraw :: Account -> Int -> STM ()<br>withdraw acc amount = do<br> bal <- readTVar acc<br> writeTVar acc (bal - amount)</div>
<div> </div>
<div>main = do<br> account <- atomically $ newTVar 100<br> atomically $ withdraw account 50<br> value <- atomically $ readTVar account<br> print value</div><br><br>
<div><span class="gmail_quote">On 12/23/07, <b class="gmail_sendername">Galchin Vasili</b> <<a href="mailto:vigalchin@gmail.com">vigalchin@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hello,<br><br> My brain is a "out to lunch". I have read the paper "Beautiful Concurrency" (as well as a bunch of "gaming" papers regarding multi cores). I am playing with the "Account" example in the paper. In the paper, the alias "type Account = TVar Int" is used. I want to actually apply the function "withdraw" to an example "Account" parameter. I keep getting a type check error. Can someone give me a concrete example of
<br><br>> withdraw ......<br><br>??<br><br>Kind regards, Vasya<br><br><br>_______________________________________________<br>Haskell-Cafe mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Haskell-Cafe@haskell.org">
Haskell-Cafe@haskell.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a>
<br><br></blockquote></div><br>