Readline read_history and write_history addition
gale at sefer.org
Tue Jan 22 18:49:34 EST 2008
Ian Lynagh wrote:
> People using MonadIO can convert this into the variant that doesn't
> throw an exception by replacing
> readlineFunction args
> with something like
> (try $ readlineFunction args) >> return ()
That's in the IO monad, so not always available.
Here's an example:
In a library, you have a function that starts up an
external system, runs a calculation, then shuts
down the external system. Like this:
bracketSystem :: MonadIO m => m a -> m a
bracketSystem x = do
ret <- x
Now you would really like to wrap that in bracket
to make sure that "shutDownSystem" is called even
when an IO exception is thrown. But unfortunately,
bracket is currently not available for MonadIO,
nor is there any way to emulate it AFIK.
(This is a "maybe" for HaskellPrime:
So the best you can do is make sure not to do anything
inside "x" that is likely to throw an IO exception. That
way, you'll only be left with zombies and other mess when
the hard disk fills up, or other rare and serious conditions.
If we start throwing IO exceptions for common and minor
occurrences like no readline history available, libraries like
this become impossible to write in Haskell. And code
that has already been written becomes unusable.
More information about the Libraries