[Haskell-cafe] Mixing IO and STM

Brian Sniffen brian.sniffen at gmail.com
Thu Dec 29 15:02:01 EST 2005


> test_Cubby =
>   do
>     tv <- newTVar 0

You've almost got it!  But "newTVar 0" has type STM Tvar, and you're
trying to use it in the IO monad.  So just say "tv <- atomically
(newTVar 0)" and you're set.  Do notice that you'll see output like
this:

co"nisnusmeer t6 "6
"
"c"oinnssuemret  61""

""cionnsseurmte  95""

""icnosnesrutm e2 "9

since the two threads are interleaved.

--
Brian T. Sniffen
bts at alum.mit.edu    or    brian.sniffen at gmail.com
http://www.evenmere.org/~bts


More information about the Haskell-Cafe mailing list