2 {-# OPTIONS_GHC -XNoImplicitPrelude #-}
3 {-# OPTIONS_HADDOCK hide #-}
4 -----------------------------------------------------------------------------
6 -- Module : GHC.Classes
7 -- Copyright : (c) The University of Glasgow, 1992-2002
8 -- License : see libraries/base/LICENSE
10 -- Maintainer : cvs-ghc@haskell.org
11 -- Stability : internal
12 -- Portability : non-portable (GHC extensions)
16 -----------------------------------------------------------------------------
18 module GHC.Classes where
23 infix 4 ==, /=, <, <=, >=, >
27 default () -- Double isn't available yet
29 -- | The 'Eq' class defines equality ('==') and inequality ('/=').
30 -- All the basic datatypes exported by the "Prelude" are instances of 'Eq',
31 -- and 'Eq' may be derived for any datatype whose constituents are also
34 -- Minimal complete definition: either '==' or '/='.
37 (==), (/=) :: a -> a -> Bool
42 -- | The 'Ord' class is used for totally ordered datatypes.
44 -- Instances of 'Ord' can be derived for any user-defined
45 -- datatype whose constituent types are in 'Ord'. The declared order
46 -- of the constructors in the data declaration determines the ordering
47 -- in derived 'Ord' instances. The 'Ordering' datatype allows a single
48 -- comparison to determine the precise ordering of two objects.
50 -- Minimal complete definition: either 'compare' or '<='.
51 -- Using 'compare' can be more efficient for complex types.
53 class (Eq a) => Ord a where
54 compare :: a -> a -> Ordering
55 (<), (<=), (>), (>=) :: a -> a -> Bool
56 max, min :: a -> a -> a
58 compare x y = if x == y then EQ
59 -- NB: must be '<=' not '<' to validate the
60 -- above claim about the minimal things that
61 -- can be defined for an instance of Ord:
62 else if x <= y then LT
65 x < y = case compare x y of { LT -> True; _ -> False }
66 x <= y = case compare x y of { GT -> False; _ -> True }
67 x > y = case compare x y of { GT -> True; _ -> False }
68 x >= y = case compare x y of { LT -> False; _ -> True }
70 -- These two default methods use '<=' rather than 'compare'
71 -- because the latter is often more expensive
72 max x y = if x <= y then y else x
73 min x y = if x <= y then x else y
75 -- OK, so they're technically not part of a class...:
80 (&&) :: Bool -> Bool -> Bool
85 (||) :: Bool -> Bool -> Bool