Exception handling when using STUArray

Sterling Clover wrote:
there's no standard way that I know of besides "inspection" to determine if code might throw an exception, and this is particularly the case with the dreaded lazy IO of prelude functions.
The following old message showed even two ways of doing exactly that -- in Haskell, with no external tools. Exceptions in types and exception-free programming http://www.haskell.org/pipermail/haskell/2004-June/014271.html The third way described in the message -- ensuring that exceptions will never occur -- was further developed as lightweight static capabilities.
And as per a recent discussion on libraries, it's still a royal pain to catch IO exceptions in monads with an IO base.
That is again very easy. Takusen uses a CaughtMonadIO -- which includes a wide range of monads: IO itself and various transformations of it. I am extensively using a variant written by Jesse Tov based on the Takusen's idea. His code defines two classes: EMonad and EMonadIO -- which enclose most of the interesting monads. The latter is the subclass of the former and also allows arbitrary IO (via liftIO). In either case, I use gthrow, gbracket, gcatch, ghandle, gfinally, etc. -- without even thinking which Monad I'm in and how error handling is actually implemented (via ErrorT or via IO exceptions). It works universally for most of monads of interest.
participants (1)
-
oleg@okmij.org