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

Thomas M. DuBuisson thomas.dubuisson at
Mon May 5 22:42:57 EDT 2008

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 ==

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?


More information about the Libraries mailing list