1 {-# LANGUAGE CPP, 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 -- * Implicit paramaters

32 IP(..),

34 -- * Equality and ordering

38 -- * Functions over Bool

41 -- * Integer arithmetic

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

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

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

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

64 ip :: a

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

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

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

70 -- instances of 'Eq'.

71 --

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

73 --

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

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

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

93 Eq h)

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

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

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

127 deriving instance Eq Word

140 (==) = eqInt

141 (/=) = neInt

143 {-# INLINE eqInt #-}

144 {-# INLINE neInt #-}

171 #endif

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

175 --

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

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

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

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

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

181 --

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

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

184 --

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

192 -- above claim about the minimal things that

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

195 else GT

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

203 -- because the latter is often more expensive

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

218 Ord h)

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

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

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

251 other -> other

255 deriving instance Ord Word

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

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

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

270 else GT

281 else GT

290 (<) = ltInt

291 (<=) = leInt

292 (>=) = geInt

293 (>) = gtInt

295 {-# INLINE gtInt #-}

296 {-# INLINE geInt #-}

297 {-# INLINE ltInt #-}

298 {-# INLINE leInt #-}

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

316 -- Boolean functions

318 -- | Boolean \"and\"

323 -- | Boolean \"or\"

328 -- | Boolean \"not\"

334 ------------------------------------------------------------------------

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

336 -- put them

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

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

342 -- code has problems with overflow:

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

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

355 where

359 {- *************************************************************

360 * *

361 * Constraint tuples *

362 * *

363 ************************************************************* -}

390 c17)

392 c17)

447 c31)

450 c31)

532 c45)

536 c45)

645 c59)

650 c59)