<div>{- compile with ghc --make stm.hs -}</div>
<div>module Main where<br>import Control.Concurrent.STM</div>
<div>&nbsp;</div>
<div>type Account = TVar Int</div>
<div>&nbsp;</div>
<div>withdraw :: Account -&gt; Int -&gt; STM ()<br>withdraw acc amount = do<br>&nbsp;&nbsp;&nbsp; bal &lt;- readTVar acc<br>&nbsp;&nbsp;&nbsp; writeTVar acc (bal - amount)</div>
<div>&nbsp;</div>
<div>main = do<br>&nbsp;&nbsp;&nbsp; account &lt;- atomically $ newTVar 100<br>&nbsp;&nbsp;&nbsp; atomically $ withdraw account 50<br>&nbsp;&nbsp;&nbsp; value &lt;- atomically $ readTVar account<br>&nbsp;&nbsp;&nbsp; print value</div><br><br>
<div><span class="gmail_quote">On 12/23/07, <b class="gmail_sendername">Galchin Vasili</b> &lt;<a href="mailto:vigalchin@gmail.com">vigalchin@gmail.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hello,<br><br>&nbsp;&nbsp;&nbsp;&nbsp; My brain is a &quot;out to lunch&quot;. I have read the paper &quot;Beautiful Concurrency&quot; (as well as a bunch of &quot;gaming&quot; papers regarding multi cores). I am playing with the &quot;Account&quot; example in the paper. In the paper, the alias &quot;type Account = TVar Int&quot; is used.&nbsp; I want to actually apply the function &quot;withdraw&quot; to an example &quot;Account&quot; parameter. I keep getting a type check error. Can someone give me a concrete example of 
<br><br>&gt; 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>