base package

Simon Marlow marlowsd at gmail.com
Thu Feb 21 10:42:24 CET 2013


On 20/02/13 15:40, Joachim Breitner wrote:

> +-- | This exception is thrown by the 'fail' method of the 'Monad' 'IO' instance.
> +--
> +--   The Exception instance of IOException will also catch this, converting the
> +--   IOFail to a UserError, for compatibility and consistency with the Haskell
> +--   report
> +data IOFail = IOFail String
> +
> +instance Typeable IOFail -- deriving does not work without package
> +instance Show IOFail     -- name changes to GHC
> +instance Exception IOFail
> +

I like the idea of making IOFail a separate exception type.

> -instance Exception IOException
> +instance Exception IOException where
> +    toException = SomeException
> +    fromException e = case cast e of
> +        Just (IOFail s) -> Just (userError s)
> +        Nothing -> cast e

I think that should be

 > +    fromException (SomeException e) = case cast e of
 > +        Just (IOFail s) -> Just (userError s)
 > +        Nothing -> cast e

Otherwise it will typecheck but not work (hurrah for dynamic typing).

The trick is indeed neat, but only if it is possible to make IOFail 
completely invisible.  If it isn't possible to make it completely 
invisible, then I would prefer IOFail to be a first-class exception type 
without the special trick to coerce it to IOException, and accept the 
API breakage.  I don't think it's a good idea to have special magic in 
the exception hierarchy - other people would start doing it too, then 
we'd have a mess.

Cheers,
	Simon




More information about the Glasgow-haskell-users mailing list