Error manipulation functions
Simon Marlow
simonmar at microsoft.com
Mon Aug 1 07:35:24 EDT 2005
On 28 July 2005 15:05, Ian Lynagh wrote:
> I couldn't see a way to write any of these functions without using
> GHC.IOBase. Did I miss one?
>
> If not, can they (or something that would allow them to be written)
> please be added to System.IO.Error?
>
>
> import GHC.IOBase ( IOException(ioe_location),
> IOErrorType(UnsupportedOperation, HardwareFault) )
>
> add_to_error_loc :: Exception -> String -> Exception
> add_to_error_loc (IOException ioe) s
> = IOException $ ioe { ioe_location = s ++ ": " ++ ioe_location
> ioe } add_to_error_loc e _ = e
I don't think all implementations have a "location" field in their
IOErrors, since it isn't required by Haskell 98. Interestingly, the GHC
implementation of mkIOError fills in the location field rather than the
description field, so I suspect you could use mkIOError to construct
add_to_error_loc.
One possibility is to add support for the location of an IOError to
System.IO.Error.
> isUnsupportedOperationError :: IOError -> Bool
> isUnsupportedOperationError = isUnsupportedOperationErrorType .
> ioeGetErrorType
>
> isUnsupportedOperationErrorType :: IOErrorType -> Bool
> isUnsupportedOperationErrorType UnsupportedOperation = True
> isUnsupportedOperationErrorType _ = False
This one is easier. I'm happy for this to go in, if there are no
objections. There are some other ErrorTypes that GHC supports that
aren't in H98, IIRC.
Cheers,
Simon
More information about the Libraries
mailing list