+
+-- I/O errors
+-- ----------
+
+-- construct an IO error
+--
+mkIOError :: IOErrorType -> String -> Maybe FilePath -> Maybe Handle -> IOError
+mkIOError errTy loc path hdl =
+ IOException $ IOError hdl errTy loc "" path
+
+-- pre-defined error types corresponding to the predicates in the standard
+-- library `IO'
+--
+alreadyExistsErrorType, doesNotExistErrorType, alreadyInUseErrorType,
+ fullErrorType, eofErrorType, illegalOperationType, permissionErrorType,
+ userErrorType :: IOErrorType
+alreadyExistsErrorType = AlreadyExists
+doesNotExistErrorType = NoSuchThing
+alreadyInUseErrorType = ResourceBusy
+fullErrorType = ResourceExhausted
+eofErrorType = EOF
+illegalOperationType = IllegalOperation
+permissionErrorType = PermissionDenied
+userErrorType = OtherError
+
+-- add location information and possibly a path and handle to an existing I/O
+-- error
+--
+-- * if no file path or handle is given, the corresponding value that's in the
+-- error is left unaltered
+--
+annotateIOError :: IOError
+ -> String
+ -> Maybe FilePath
+ -> Maybe Handle
+ -> IOError
+annotateIOError (IOException (IOError hdl errTy _ str path)) loc opath ohdl =
+ IOException (IOError (hdl `mplus` ohdl) errTy loc str (path `mplus` opath))
+ where
+ Nothing `mplus` ys = ys
+ xs `mplus` _ = xs
+annotateIOError exc _ _ _ =
+ exc
+
+
+-- Result value checks
+-- -------------------