Deriving instance for Foreign.C.Error.Errno (trac 2261)

Errno, the Haskell encapsulation of the CInt 'errno' value, should be an instance of the commonly used type classes so higher level data structures that include it aren't bothered. This change will break code that has custom instances for Errno, but this should be little (if any) code. A patch is attached to the trac ticket to derive Show and Ord while Eq remains a custom instance. One could argue that, like Eq, Show and Ord should be customized to provide a identical result for all 'invalid' errno's - any thoughts on if this is necessary and what the corner case result would be? http://hackage.haskell.org/trac/ghc/ticket/2261 Thomas P.S. Traveling soon, so I won't be responsive - sorry.

On Mon, 2008-05-05 at 08:16 -0400, Thomas M. DuBuisson wrote:
Errno, the Haskell encapsulation of the CInt 'errno' value, should be an instance of the commonly used type classes so higher level data structures that include it aren't bothered.
This change will break code that has custom instances for Errno, but this should be little (if any) code.
A patch is attached to the trac ticket to derive Show and Ord while Eq remains a custom instance. One could argue that, like Eq, Show and Ord should be customized to provide a identical result for all 'invalid' errno's - any thoughts on if this is necessary and what the corner case result would be?
Having it an instance of Ord and Show seems fine. If the Eq instance equates all the invalid errnos then the Ord instance should do so too because it is important that: compare a b == Eq <=> a == b Duncan

Duncan Coutts wrote: | If the Eq instance equates all the invalid errnos then the Ord instance | should do so too because it is important that | compare a b == Eq <=> a == b Unfortunatly the default is not equal:
instance Eq Errno where errno1@(Errno no1) == errno2@(Errno no2) | isValidErrno errno1 && isValidErrno errno2 = no1 == no2 | otherwise
So if the errnos are invalid compare could return: A) {GT or LT} -- thus (a < b && b < a), no good B) EQ -- Contradicting the current definition of Eq C) Option 'B' and change the definition of Eq (allowing invalid == invalid) I encourage option C, which basically means deriving all the instances (the only invalid Errno is -1). I'm not sure how this affects existing code using Errno, but if its all static checks (unkErr == ePERM) then things should still be fine. Anyone know of the reason for or a use of the current behavior? Thomas
participants (2)
-
Duncan Coutts
-
Thomas M. DuBuisson