Leon Smith | 30 Jul 19:12 2011
Picon

Issue with monad-control

Since I need bracket on application-specific monads,  and Snap is
thinking about moving to monad-control,  I started digging into the
issue this weekend at HacPhi.   But here's some food for thought;
before you run this test case yourself,  you should work out what it
should do.

import qualified Prelude
import Prelude hiding (putStrLn)
import Control.Monad.State.Strict
import Control.Monad.Trans
import Control.Exception.Control

type M = StateT Int IO

putStrLn = liftIO . Prelude.putStrLn

test :: IO ((),Int)
test = runStateT (do
                      x <- get
                      putStrLn ("Prologue with state: " ++ show x)
                      bracket
                          (putStrLn "Hello!" >> put 2)
                          (\ () -> do
                             x <- get
                             putStrLn ("Ending with state: " ++ show x)
                             put 3)
                          (\ () -> do
                             x <- get
                             putStrLn ("Doing with state: " ++ show x)
                             put 4)
                      x' <- get
                      putStrLn ("Epilogue with state: " ++ show x')
                 ) 1


Gmane