On 01/12/12 17:23, Gregory Crosswhite wrote: > Indeed, and in fact this situation is a very natural occurrence whenever > you are writing code that takes an arbitrary IO action, executes it, and > then returns either the result or the exception that it threw. The code > that I last used for this took advantage of catchJust and looked roughly > like the following: > > execute :: IO a → IO (Either SomeException a) > execute action = > catchJust > (\e → case fromException e of {Just (_ :: AsyncException) → Nothing; _ → > Just e}) > (Right <$> action) > (return . Left) > > Cheers, > Greg
Ugh, I have no idea why the spacing got eaten; it was meant to look like: execute :: IO a -> IO (Either SomeException a) execute action = catchJust (\e -> case fromException e of Just (_ :: AsyncException) -> Nothing; _ -> Just e ) (Right <$> action) (return . Left) Cheers, Greg _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe