[Haskell-beginners] How are complex Errors implemented

Christopher Howard christopher.howard at frigidcode.com
Wed Jun 8 18:45:18 CEST 2011


So, I know from the source code at hackage that the IOException type is
implemented with multiple fields, like so:

data IOException
 = IOError {
     ioe_handle   :: Maybe Handle,   -- the handle used by the action
flagging
                                     -- the error.
     ioe_type     :: IOErrorType,    -- what it was.
     ioe_location :: String,         -- location.
     ioe_description :: String,      -- error type specific information.
     ioe_errno    :: Maybe CInt,     -- errno leading to this error, if any.
     ioe_filename :: Maybe FilePath  -- filename the error is related to.
   }
    deriving Typeable

However, the hackage docs for Control.Monad.Error indicates that there
is an Error IOException instance. But the Error class requires the
implementation of at least one of two functions, noMsg and strMsg, which
create an error with either a String or with nothing. Question: in the
implementation of Error IOException, how does noMsg or strMsg create new
IOExceptions when they don't take all the required information? (I
couldn't find the implementation in the source code by clicking the
"source" buttons on the page... maybe somebody could post that.)

Reason I ask: Lets say I want to create my own error type which is a
member of Error, but has multiple record fields. How would I implement
noMsg and strMsg?

-- 
frigidcode.com
theologia.indicium.us



More information about the Beginners mailing list