Move MonadIO to base

Yitzchak Gale gale at sefer.org
Sun Apr 11 11:35:12 EDT 2010


Twan van Laarhoven wrote:
> If MonadIO were in base, then the base library itself could also use it. For
> example the functions in System.IO could be lifted to work on any MonadIO
> monad. Whether that is a good idea is completely orthogonal to this
> discussion, however.

The main problem is that exceptions don't work well with
MonadIO in GHC. So really MonadIO is currently only a toy and
cannot be used in production code.

The reason for this is that just about any operation involving exceptions
ultimately depends (via the source code of base library functions)
on the function

block :: IO a -> IO a

and that type is hard-wired in a GHC primitive. Additional primitives
to support things like

startBlocking :: IO ()
stopBlocking :: IO ()

which would play well with MonadIO, could be added to
GHC, but they would lose important optimizations.
I'm not sure about the order of magnitude of the cost - whether
it would just make things run more slowly, or render them
completely unusable. If the former, I am in favor of this
proposal, but only combined with the addition of GHC support
for startBlocking and stopBlocking. If the latter, then
there is no point to this proposal.

Regards,
Yitz


More information about the Libraries mailing list