1 {-# OPTIONS -fglasgow-exts #-}
6 (===), (/==) :: a -> a -> Bool
8 -- x /= y = not (x == y)
9 -- x == y = not (x /= y)
11 (/==) x y = mynot ((===) x y)
14 data EOrdering = ELT | EEQ | EGT
20 class (EEq a) => EOrd a where
21 ecompare :: a -> a -> EOrdering
22 (<<), (<<=), (>>>=), (>>>):: a -> a -> Bool
23 emax, emin :: a -> a -> a
25 -- An instance of Ord should define either compare or <=
26 -- Using compare can be more efficient for complex types.
29 | x <<= y = ELT -- NB: must be '<=' not '<' to validate the
30 -- above claim about the minimal things that can
31 -- be defined for an instance of Ord
34 x <<= y = case ecompare x y of { EGT -> False; _other -> True }
35 x << y = case ecompare x y of { ELT -> True; _other -> False }
36 x >>>= y = case ecompare x y of { ELT -> False; _other -> True }
37 x >>> y = case ecompare x y of { EGT -> True; _other -> False }
39 -- These two default methods use '>' rather than compare
40 -- because the latter is often more expensive
41 emax x y = if x >>> y then x else y
42 emin x y = if x >>> y then y else x
47 ezeroInt, eoneInt, etwoInt, emaxInt, eminInt :: EInt
51 eminInt = EI (-2147483648#) -- GHC <= 2.09 had this at -2147483647
52 emaxInt = EI 2147483647#
53 eeqInt (EI x) (EI y) = x ==# y
54 eneInt (EI x) (EI y) = x /=# y
56 instance EEq EInt where
57 (===) x y = x `eeqInt` y
58 (/==) x y = x `eneInt` y
60 main = putStr (if (ezeroInt === eoneInt) then "no!\n" else "yes!\n")