How are complex Errors implemented

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

On Wed, Jun 8, 2011 at 12:45, Christopher Howard
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?
However you want. The thing to keep in mind is that those are the required constructors, but need not be the *only* constructors; your code would use other constructors that provide more information, while noMsg and strMsg are used by generic code that wouldn't know what to do with your additional fields anyway. So pick saneish defaults.
participants (2)
-
Brandon Allbery
-
Christopher Howard