bracket, (un)block and MonadIO

Simon Marlow simonmar@microsoft.com
Thu, 4 Sep 2003 10:45:17 +0100


> However, the definition of bracket relies on block and=20
> unblock, which have the
> following types:
> > bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c
> > block :: IO a -> IO a
> > unblock :: IO a -> IO a
>=20
> This forces f to be an IO action in the above withQuery=20
> function.  If bracket,
> block, and unblock had these types, my helper function would=20
> be well typed:
>=20
> > bracket :: MonadIO m =3D> m a -> (a -> m b) -> (a -> m c) -> m c
> > block :: MonadIO m =3D> m a -> m a
> > unblock :: MonadIO m =3D> m a -> m a
>
> Would anything prevent block, unblock, bracket (and other=20
> similar functions
> working on IO actions) from being generalized to all intances=20
> of MonadIO?

I'm afraid I can't see a way to generalise the types of block and
unblock, since they are based on underlying primitives that really do
have type (IO a -> IO a).  Perhaps if your monad is isomorphic to IO, it
could be done, but otherwise I don't think it's possible.  Unless I'm
missing something.
=20
Cheers,
	Simon