Proposed addition to stm: atomicallyIO and afterCommit

Isaac Dupree ml at isaac.cedarswampstudios.org
Thu Feb 25 14:21:39 EST 2010


On 02/24/10 05:07, Simon Marlow wrote:
> Simon just pointed out to me that this is quite closely related, though
> more general:
>
> http://hackage.haskell.org/package/stm-io-hooks
> http://www.haskell.org/haskellwiki/New_monads/MonadAdvSTM

Because of those ideas that are already floating around, I think this 
one is misleading.  In those, the 
afterCommit::IO(something)->STM(something) means even if it's not the 
last statement in the monad, to execute the IO when the transaction 
commits.  Which has notable effects on the compositionality of STM (not 
sure about "good" or "bad" effects, but it's notable).

As a coder, instead of Left and Right or atomicallyIO/afterCommit, I 
think I'd tend to write those functions inlined where it's readable;

join{-IO-} $ atomically $ do{-STM-}
   ...
     return $ do{-IO-}
       ...
   ...

(I do use that sort of which-monad-is-it comment in my code whenever 
it's not utterly obvious... Haskell doesn't provide any equally concise 
way to write those notes such that it will be checked by the compiler, 
sadly.)

-Isaac


More information about the Libraries mailing list