| Copyright | (c) The University of Glasgow 1992-2002 |
|---|---|
| License | see libraries/base/LICENSE |
| Maintainer | cvs-ghc@haskell.org |
| Stability | internal |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
GHC.Classes
Description
Basic classes.
Synopsis
- class IP (x :: Symbol) a | x -> a where
- ip :: a
- class Eq a where
- class Eq a => Ord a where
- eqInt :: Int -> Int -> Bool
- neInt :: Int -> Int -> Bool
- eqWord :: Word -> Word -> Bool
- neWord :: Word -> Word -> Bool
- eqChar :: Char -> Char -> Bool
- neChar :: Char -> Char -> Bool
- eqFloat :: Float -> Float -> Bool
- eqDouble :: Double -> Double -> Bool
- gtInt :: Int -> Int -> Bool
- geInt :: Int -> Int -> Bool
- leInt :: Int -> Int -> Bool
- ltInt :: Int -> Int -> Bool
- compareInt :: Int -> Int -> Ordering
- compareInt# :: Int# -> Int# -> Ordering
- gtWord :: Word -> Word -> Bool
- geWord :: Word -> Word -> Bool
- leWord :: Word -> Word -> Bool
- ltWord :: Word -> Word -> Bool
- compareWord :: Word -> Word -> Ordering
- compareWord# :: Word# -> Word# -> Ordering
- (&&) :: Bool -> Bool -> Bool
- (||) :: Bool -> Bool -> Bool
- not :: Bool -> Bool
- divInt# :: Int# -> Int# -> Int#
- modInt# :: Int# -> Int# -> Int#
Implicit paramaters
class IP (x :: Symbol) a | x -> a where Source #
The syntax ?x :: a is desugared into IP "x" a
IP is declared very early, so that libraries can take
advantage of the implicit-call-stack feature
Equality and ordering
The Eq class defines equality (== ) and inequality (/= ).
All the basic datatypes exported by the Prelude are instances of Eq ,
and Eq may be derived for any datatype whose constituents are also
instances of Eq .
The Haskell Report defines no laws for Eq . However, instances are
encouraged to follow these properties:
Instances
Instances details
Note that due to the presence of NaN, Double 's Eq instance does not
satisfy reflexivity.
>>>0/0 == (0/0 :: Double)False
Also note that Double 's Eq instance does not satisfy substitutivity:
>>>0 == (-0 :: Double)True>>>recip 0 == recip (-0 :: Double)False
Note that due to the presence of NaN, Float 's Eq instance does not
satisfy reflexivity.
>>>0/0 == (0/0 :: Float)False
Also note that Float 's Eq instance does not satisfy extensionality:
>>>0 == (-0 :: Float)True>>>recip 0 == recip (-0 :: Float)False
class Eq a => Ord a where Source #
The Ord class is used for totally ordered datatypes.
Instances of Ord can be derived for any user-defined datatype whose
constituent types are in Ord . The declared order of the constructors in
the data declaration determines the ordering in derived Ord instances. The
Ordering datatype allows a single comparison to determine the precise
ordering of two objects.
Ord , as defined by the Haskell report, implements a total order and has the
following properties:
- Comparability
x <= y || y <= x=True- Transitivity
- if
x <= y && y <= z=True, thenx <= z=True - Reflexivity
x <= x=True- Antisymmetry
- if
x <= y && y <= x=True, thenx == y=True
The following operator interactions are expected to hold:
x >= y=y <= xx < y=x <= y && x /= yx > y=y < xx < y=compare x y == LTx > y=compare x y == GTx == y=compare x y == EQmin x y == if x <= y then x else y=Truemax x y == if x >= y then x else y=True
Note that (7.) and (8.) do not require min and max to return either of
their arguments. The result is merely required to equal one of the
arguments in terms of (==) .
Minimal complete definition: either compare or <= .
Using compare can be more efficient for complex types.
Methods
compare :: a -> a -> Ordering Source #
(<) :: a -> a -> Bool infix 4 Source #
(<=) :: a -> a -> Bool infix 4 Source #
(>) :: a -> a -> Bool infix 4 Source #
Instances
Instances details
Instance details
Defined in GHC.Classes
Instance details
Defined in GHC.Classes
Instance details
Defined in GHC.Classes
Instance details
Defined in GHC.Classes
Note that due to the presence of NaN, Double 's Ord instance does not
satisfy reflexivity.
>>>0/0 <= (0/0 :: Double)False
Also note that, due to the same, Ord 's operator interactions are not
respected by Double 's instance:
>>>(0/0 :: Double) > 1False>>>compare (0/0 :: Double) 1GT
Instance details
Defined in GHC.Classes
Note that due to the presence of NaN, Float 's Ord instance does not
satisfy reflexivity.
>>>0/0 <= (0/0 :: Float)False
Also note that, due to the same, Ord 's operator interactions are not
respected by Float 's instance:
>>>(0/0 :: Float) > 1False>>>compare (0/0 :: Float) 1GT
Instance details
Defined in GHC.Classes
Instance details
Defined in GHC.Classes
Instance details
Defined in GHC.Classes
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c) -> (a, b, c) -> Ordering Source #
(<) :: (a, b, c) -> (a, b, c) -> Bool Source #
(<=) :: (a, b, c) -> (a, b, c) -> Bool Source #
(>) :: (a, b, c) -> (a, b, c) -> Bool Source #
(>=) :: (a, b, c) -> (a, b, c) -> Bool Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d) -> (a, b, c, d) -> Ordering Source #
(<) :: (a, b, c, d) -> (a, b, c, d) -> Bool Source #
(<=) :: (a, b, c, d) -> (a, b, c, d) -> Bool Source #
(>) :: (a, b, c, d) -> (a, b, c, d) -> Bool Source #
(>=) :: (a, b, c, d) -> (a, b, c, d) -> Bool Source #
max :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source #
min :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e) -> (a, b, c, d, e) -> Ordering Source #
(<) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool Source #
(<=) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool Source #
(>) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool Source #
(>=) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool Source #
max :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source #
min :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Ordering Source #
(<) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool Source #
(<=) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool Source #
(>) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool Source #
(>=) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool Source #
max :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source #
min :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Ordering Source #
(<) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool Source #
(<=) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool Source #
(>) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool Source #
(>=) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool Source #
max :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source #
min :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Ordering Source #
(<) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool Source #
(<=) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool Source #
(>) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool Source #
(>=) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool Source #
max :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) Source #
min :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Ordering Source #
(<) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool Source #
(<=) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool Source #
(>) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool Source #
(>=) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool Source #
max :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) Source #
min :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Ordering Source #
(<) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool Source #
(<=) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool Source #
(>) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool Source #
(>=) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool Source #
max :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) Source #
min :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Ordering Source #
(<) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool Source #
(<=) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool Source #
(>) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool Source #
(>=) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool Source #
max :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) Source #
min :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Ordering Source #
(<) :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Bool Source #
(<=) :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Bool Source #
(>) :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Bool Source #
(>=) :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Bool Source #
max :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) Source #
min :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Ordering Source #
(<) :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Bool Source #
(<=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Bool Source #
(>) :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Bool Source #
(>=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Bool Source #
max :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) Source #
min :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Ordering Source #
(<) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Bool Source #
(<=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Bool Source #
(>) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Bool Source #
(>=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Bool Source #
max :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source #
min :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source #
Instance details
Defined in GHC.Classes
Methods
compare :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Ordering Source #
(<) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Bool Source #
(<=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Bool Source #
(>) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Bool Source #
(>=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Bool Source #
max :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source #
min :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source #
Monomorphic equality operators
Matching on class methods (e.g. (==)) in rewrite rules tends to be a bit
fragile. For instance, consider this motivating example from the bytestring
library,
break :: (Word8 -> Bool) -> ByteString -> (ByteString, ByteString)
breakByte :: Word8 -> ByteString -> (ByteString, ByteString)
{-# RULES "break -> breakByte" forall a. break (== x) = breakByte x #-}
Here we have two functions, with breakByte providing an optimized
implementation of break where the predicate is merely testing for equality
with a known Word8. As written, however, this rule will be quite fragile as
the (==) class operation rule may rewrite the predicate before our break
rule has a chance to fire.
For this reason, most of the primitive types in base have Eq and Ord
instances defined in terms of helper functions with inlinings delayed to phase
1. For instance, Word8's Eq instance looks like,
instance Eq Word8 where
(==) = eqWord8
(/=) = neWord8
eqWord8, neWord8 :: Word8 -> Word8 -> Bool
eqWord8 (W8# x) (W8# y) = ...
neWord8 (W8# x) (W8# y) = ...
{-# INLINE [1] eqWord8 #-}
{-# INLINE [1] neWord8 #-}
This allows us to save our break rule above by rewriting it to instead match
against eqWord8,
{-# RULES "break -> breakByte" forall a. break (eqWord8 x) = breakByte x #-}
Currently this is only done for (, == )(, /= )(, < )(, <= )(,
and > )( for the types in GHC.Word and GHC.Int.>= )