18662ad53964061208aa83fc16c9c944dd1c5c74

1 {-# LANGUAGE Trustworthy #-}

2 {-# LANGUAGE NoImplicitPrelude, MagicHash, StandaloneDeriving, BangPatterns,

3 KindSignatures, DataKinds, ConstraintKinds,

4 MultiParamTypeClasses, FunctionalDependencies #-}

5 {-# LANGUAGE AllowAmbiguousTypes #-}

6 -- ip :: IP x a => a is strictly speaking ambiguous, but IP is magic

8 {-# OPTIONS_GHC -fno-warn-unused-imports #-}

9 -- -fno-warn-unused-imports needed for the GHC.Tuple import below. Sigh.

11 {-# OPTIONS_GHC -fno-warn-unused-top-binds #-}

12 -- -fno-warn-unused-top-binds is there (I hope) to stop Haddock complaining

13 -- about the constraint tuples being defined but not used

15 {-# OPTIONS_HADDOCK hide #-}

16 -----------------------------------------------------------------------------

17 -- |

18 -- Module : GHC.Classes

19 -- Copyright : (c) The University of Glasgow, 1992-2002

20 -- License : see libraries/base/LICENSE

21 --

22 -- Maintainer : cvs-ghc@haskell.org

23 -- Stability : internal

24 -- Portability : non-portable (GHC extensions)

25 --

26 -- Basic classes.

27 --

28 -----------------------------------------------------------------------------

31 IP(..),

38 -- GHC.Magic is used in some derived instances

51 -- | The syntax @?x :: a@ is desugared into @IP "x" a@

52 -- IP is declared very early, so that libraries can take

53 -- advantage of the implicit-call-stack feature

55 ip :: a

58 -- | The 'Eq' class defines equality ('==') and inequality ('/=').

59 -- All the basic datatypes exported by the "Prelude" are instances of 'Eq',

60 -- and 'Eq' may be derived for any datatype whose constituents are also

61 -- instances of 'Eq'.

62 --

63 -- Minimal complete definition: either '==' or '/='.

64 --

68 {-# INLINE (/=) #-}

69 {-# INLINE (==) #-}

72 {-# MINIMAL (==) | (/=) #-}

84 Eq h)

109 {-# SPECIALISE instance Eq [[Char]] #-}

110 {-# SPECIALISE instance Eq [Char] #-}

111 {-# SPECIALISE instance Eq [Int] #-}

118 deriving instance Eq Word

131 (==) = eqInt

132 (/=) = neInt

134 {-# INLINE eqInt #-}

135 {-# INLINE neInt #-}

140 -- | The 'Ord' class is used for totally ordered datatypes.

141 --

142 -- Instances of 'Ord' can be derived for any user-defined

143 -- datatype whose constituent types are in 'Ord'. The declared order

144 -- of the constructors in the data declaration determines the ordering

145 -- in derived 'Ord' instances. The 'Ordering' datatype allows a single

146 -- comparison to determine the precise ordering of two objects.

147 --

148 -- Minimal complete definition: either 'compare' or '<='.

149 -- Using 'compare' can be more efficient for complex types.

150 --

157 -- NB: must be '<=' not '<' to validate the

158 -- above claim about the minimal things that

159 -- can be defined for an instance of Ord:

161 else GT

168 -- These two default methods use '<=' rather than 'compare'

169 -- because the latter is often more expensive

172 {-# MINIMAL compare | (<=) #-}

184 Ord h)

209 {-# SPECIALISE instance Ord [[Char]] #-}

210 {-# SPECIALISE instance Ord [Char] #-}

211 {-# SPECIALISE instance Ord [Int] #-}

217 other -> other

221 deriving instance Ord Word

223 -- We don't use deriving for Ord Char, because for Ord the derived

224 -- instance defines only compare, which takes two primops. Then

225 -- '>' uses compare, and therefore takes two primops instead of one.

236 else GT

247 else GT

256 (<) = ltInt

257 (<=) = leInt

258 (>=) = geInt

259 (>) = gtInt

261 {-# INLINE gtInt #-}

262 {-# INLINE geInt #-}

263 {-# INLINE ltInt #-}

264 {-# INLINE leInt #-}

280 -- OK, so they're technically not part of a class...:

282 -- Boolean functions

284 -- | Boolean \"and\"

289 -- | Boolean \"or\"

294 -- | Boolean \"not\"

300 ------------------------------------------------------------------------

301 -- These don't really belong here, but we don't have a better place to

302 -- put them

306 -- Be careful NOT to overflow if we do any additional arithmetic

307 -- on the arguments... the following previous version of this

308 -- code has problems with overflow:

309 -- | (x# ># 0#) && (y# <# 0#) = ((x# -# y#) -# 1#) `quotInt#` y#

310 -- | (x# <# 0#) && (y# ># 0#) = ((x# -# y#) +# 1#) `quotInt#` y#

321 where

325 {- *************************************************************

326 * *

327 * Constraint tuples *

328 * *

329 ************************************************************* -}

356 c17)

358 c17)

413 c31)

416 c31)

498 c45)

502 c45)

611 c59)

616 c59)