remove empty dir
[ghc-hetmet.git] / compiler / ilxGen / tests / test11.hs
1 {-# OPTIONS -fglasgow-exts #-}
2
3 import PrelGHC
4
5 class  EEq a  where
6     (===), (/==)                :: a -> a -> Bool
7
8 --    x /= y            = not (x == y)
9 --    x == y            = not (x /= y)
10 --    x /= y            =  True
11     (/==) x y            = mynot  ((===) x y)
12     x === y             =  True
13
14 data EOrdering = ELT | EEQ | EGT 
15
16 mynot True = False
17 mynot False = True
18
19 {-
20 class  (EEq a) => EOrd a  where
21     ecompare             :: a -> a -> EOrdering
22     (<<), (<<=), (>>>=), (>>>):: a -> a -> Bool
23     emax, emin          :: a -> a -> a
24
25 -- An instance of Ord should define either compare or <=
26 -- Using compare can be more efficient for complex types.
27     ecompare x y
28             | x === y    = EEQ
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
32             | otherwise = EGT
33
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 }
38
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
43 -}
44
45 data EInt = EI Int#
46
47 ezeroInt, eoneInt, etwoInt, emaxInt, eminInt :: EInt
48 ezeroInt = EI 0#
49 eoneInt  = EI 1#
50 etwoInt  = EI 2#
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
55
56 instance EEq EInt where
57     (===) x y = x `eeqInt` y
58     (/==) x y = x `eneInt` y
59
60 main = putStr (if (ezeroInt === eoneInt) then "no!\n" else "yes!\n")
61