I was under the impression that STM code needed to be in its own
monad. I was looking at Control.Concurrent.STM.TChan, for example,
where signatures like this exist:
newTChan :: STM (TChan a)
readTChan :: TChan a -> STM a
writeTChan :: TChan a -> a -> STM ()
and then
newTChan :: STM (TChan a)
readTChan :: TChan a -> STM a
writeTChan :: TChan a -> a -> STM ()
I guess I should give this another look, re-read the STM paper and
check out your patch.
Regardless, simple is elegant and your Maybe solution is simple.
Thanks, Joel
On Nov 22, 2005, at 7:09 AM, Tomasz Zielonka wrote:
I am talking about Software Transactional Memory, which is in
Control.Concurrent.STM. I think you confused it with State
Transformer Monad.
In your case STM would allow you to wait simultaneously on (T)MVar and
(T)Chan. It would look like this:
logger :: TMVar () -> IO ()
logger die =
join $ atomically $
(do x <- readTChan parent
return $ do
putStrLn x
logger die)
`orElse`
(do takeTMVar die
return (return ()))
--
http://wagerlabs.com/
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe