
On Sat, Feb 2, 2008 at 1:14 PM, Yitzchak Gale
Alexander Dunlap wrote:
For instances where an exception would be too intrusive, I don't see how it would be too hard to write a wrapper function
I wrote:
In a library that does not have direct access to the IO monad, it would be not just hard - it would be impossible. That is because of type restrictions in the current versions of catch, block, and friends.
Judah Jacobson wrote:
You haven't said why something like the following would not be sufficient:
readHistoryM :: MonadIO m => String -> m Bool readHistoryM file = liftIO $ do result <- try (readHistory file) return (result == Right ())
Because a library - other than readline itself - can't force its users to do that.
OK. Here's a simplified real-world example. Say you want to write a simple library that interfaces the text-to-speech facilities available on multiple platforms. To play nicely with programs written in a monadic style, the interface might be something like:
class MonadIO m => Speech m where sayText :: String -> m () runSpeech :: m a -> IO a
instance Speech SomeSpeechSystem where sayText t = ... runSpeech x = do liftIO startSomeSpeechSystem ret <- x liftIO stopSomeSpeechSystem return ret
Unfortunately, bracket is not available. So if x throws an uncaught IO exception, you may leave around zombies, database corruption, missiles armed for launch, etc.
I've already demonstrated how a library writer can solve that problem in: http://www.haskell.org/pipermail/libraries/2008-January/009034.html -Judah