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
44 -- | The 'Ord' class is used for totally ordered datatypes.
46 -- Instances of 'Ord' can be derived for any user-defined
47 -- datatype whose constituent types are in 'Ord'. The declared order
48 -- of the constructors in the data declaration determines the ordering
49 -- in derived 'Ord' instances. The 'Ordering' datatype allows a single
50 -- comparison to determine the precise ordering of two objects.
52 -- Minimal complete definition: either 'compare' or '<='.
53 -- Using 'compare' can be more efficient for complex types.
55 class (Eq a) => Ord a where
56 compare :: a -> a -> Ordering
57 (<), (<=), (>), (>=) :: a -> a -> Bool
58 max, min :: a -> a -> a
60 compare x y = if x == y then EQ
61 -- NB: must be '<=' not '<' to validate the
62 -- above claim about the minimal things that
63 -- can be defined for an instance of Ord:
64 else if x <= y then LT
67 x < y = case compare x y of { LT -> True; _ -> False }
68 x <= y = case compare x y of { GT -> False; _ -> True }
69 x > y = case compare x y of { GT -> True; _ -> False }
70 x >= y = case compare x y of { LT -> False; _ -> True }
72 -- These two default methods use '<=' rather than 'compare'
73 -- because the latter is often more expensive
74 max x y = if x <= y then y else x
75 min x y = if x <= y then x else y
77 -- OK, so they're technically not part of a class...:
82 (&&) :: Bool -> Bool -> Bool
87 (||) :: Bool -> Bool -> Bool