[Haskell-cafe] Re: Control.Exceptions and MonadIO
robdockins at fastmail.fm
Mon Apr 24 00:04:37 EDT 2006
On Sunday 23 April 2006 02:19 pm, you wrote:
[snip some discussion]
> Perhaps something like:
> class MonadIO m => MonadIOE m where
> catch :: m a-> (Exception -> m a) -> m a
> -- etc
> instance MonadIOE m => StateT s m where ...
> instance MonadIOE m => ReaderT r m where ...
> blockIO :: IO a -> IO a
> class MonadIO m => MonadIOB m where
> getUnliftIO :: m (m a -> IO a)
> block :: m a -> m a
> block x = do
> unliftIO <- getUnliftIO
> liftIO (blockIO (unliftIO x))
> unblock :: m a -> m a
> bracket_ :: m a -> m b -> m c -> m c
> -- etc
> instance MonadIOB m => ReaderT r m where ...
> and then we could just get rid of all the other exception handling
> functions scattered all over the code base eg Prelude.catch etc.
> StateT s can be an instance of MonadIOE but not of MonadIOB because
> although it is sometimes fine to discard state changes when an exception
> arises, it is not ok to discard the state changes inside a block (or
> unblock, bracket_ etc).
> Does the above look like a good way of organising things?
I think the basic distinction is good; the added ability to "project" out the
IO monad seems to be the important point (although I wonder if the other
methods need to be in the class?).
It seems to me, however, that the devil is in the details for something like
this. It's hard to know if the whole thing hangs together without an
> (I don't know whether MonadIOB would require MonadIOE or not since I
> haven't tried to implement all these functions yet - if it did I would use
> the name MonadIOEB instead)
> I'm about to make an attempt along these lines myself since I can't go
> further in my own work without a proper exception api that doesn't drag
> everything down to concrete IO (unless someone else has already done this?)
> Also, would it be worth modifying
> http://hackage.haskell.org/trac/haskell-prime/ticket/110 to include
> something like this (someone more knowledgeable than me would have to do
Well, I created the ticket without much in the way of details -- feel free to
add a concrete proposal. I suppose we can take up discussion on the
haskell-prime list when discussion is opened on topics besides concurrency
and the class system.
> Regards, Brian.
More information about the Haskell-Cafe