44085a2efa423ff93a64ed65cc48a139630a8ac7
[ghc.git] / libraries / base / GHC / Base.hs
1 {-
2 The overall structure of the GHC Prelude is a bit tricky.
3
4 a) We want to avoid "orphan modules", i.e. ones with instance
5 decls that don't belong either to a tycon or a class
6 defined in the same module
7
8 b) We want to avoid giant modules
9
10 So the rough structure is as follows, in (linearised) dependency order
11
12
13 GHC.Prim Has no implementation. It defines built-in things, and
14 by importing it you bring them into scope.
15 The source file is GHC.Prim.hi-boot, which is just
16 copied to make GHC.Prim.hi
17
18 GHC.Base Classes: Eq, Ord, Functor, Monad
19 Types: list, (), Int, Bool, Ordering, Char, String
20
21 Data.Tuple Types: tuples, plus instances for GHC.Base classes
22
23 GHC.Show Class: Show, plus instances for GHC.Base/GHC.Tup types
24
25 GHC.Enum Class: Enum, plus instances for GHC.Base/GHC.Tup types
26
27 Data.Maybe Type: Maybe, plus instances for GHC.Base classes
28
29 GHC.List List functions
30
31 GHC.Num Class: Num, plus instances for Int
32 Type: Integer, plus instances for all classes so far (Eq, Ord, Num, Show)
33
34 Integer is needed here because it is mentioned in the signature
35 of 'fromInteger' in class Num
36
37 GHC.Real Classes: Real, Integral, Fractional, RealFrac
38 plus instances for Int, Integer
39 Types: Ratio, Rational
40 plus intances for classes so far
41
42 Rational is needed here because it is mentioned in the signature
43 of 'toRational' in class Real
44
45 GHC.ST The ST monad, instances and a few helper functions
46
47 Ix Classes: Ix, plus instances for Int, Bool, Char, Integer, Ordering, tuples
48
49 GHC.Arr Types: Array, MutableArray, MutableVar
50
51 Arrays are used by a function in GHC.Float
52
53 GHC.Float Classes: Floating, RealFloat
54 Types: Float, Double, plus instances of all classes so far
55
56 This module contains everything to do with floating point.
57 It is a big module (900 lines)
58 With a bit of luck, many modules can be compiled without ever reading GHC.Float.hi
59
60
61 Other Prelude modules are much easier with fewer complex dependencies.
62 -}
63
64 {-# LANGUAGE Unsafe #-}
65 {-# LANGUAGE CPP
66 , NoImplicitPrelude
67 , BangPatterns
68 , ExplicitForAll
69 , MagicHash
70 , UnboxedTuples
71 , ExistentialQuantification
72 , RankNTypes
73 #-}
74 -- -fno-warn-orphans is needed for things like:
75 -- Orphan rule: "x# -# x#" ALWAYS forall x# :: Int# -# x# x# = 0
76 {-# OPTIONS_GHC -fno-warn-orphans #-}
77 {-# OPTIONS_HADDOCK hide #-}
78
79 -----------------------------------------------------------------------------
80 -- |
81 -- Module : GHC.Base
82 -- Copyright : (c) The University of Glasgow, 1992-2002
83 -- License : see libraries/base/LICENSE
84 --
85 -- Maintainer : cvs-ghc@haskell.org
86 -- Stability : internal
87 -- Portability : non-portable (GHC extensions)
88 --
89 -- Basic data types and classes.
90 --
91 -----------------------------------------------------------------------------
92
93 #include "MachDeps.h"
94
95 module GHC.Base
96 (
97 module GHC.Base,
98 module GHC.Classes,
99 module GHC.CString,
100 module GHC.Magic,
101 module GHC.Types,
102 module GHC.Prim, -- Re-export GHC.Prim and [boot] GHC.Err,
103 -- to avoid lots of people having to
104 module GHC.Err -- import it explicitly
105 )
106 where
107
108 import GHC.Types
109 import GHC.Classes
110 import GHC.CString
111 import GHC.Magic
112 import GHC.Prim
113 import GHC.Err
114 import {-# SOURCE #-} GHC.IO (failIO)
115
116 import GHC.Tuple () -- Note [Depend on GHC.Tuple]
117 import GHC.Integer () -- Note [Depend on GHC.Integer]
118
119 infixr 9 .
120 infixr 5 ++
121 infixl 4 <$
122 infixl 1 >>, >>=
123 infixr 1 =<<
124 infixr 0 $, $!
125
126 infixl 4 <*>, <*, *>, <**>
127
128 default () -- Double isn't available yet
129
130 {-
131 Note [Depend on GHC.Integer]
132 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133 The Integer type is special because TidyPgm uses
134 GHC.Integer.Type.mkInteger to construct Integer literal values
135 Currently it reads the interface file whether or not the current
136 module *has* any Integer literals, so it's important that
137 GHC.Integer.Type (in patckage integer-gmp or integer-simple) is
138 compiled before any other module. (There's a hack in GHC to disable
139 this for packages ghc-prim, integer-gmp, integer-simple, which aren't
140 allowed to contain any Integer literals.)
141
142 Likewise we implicitly need Integer when deriving things like Eq
143 instances.
144
145 The danger is that if the build system doesn't know about the dependency
146 on Integer, it'll compile some base module before GHC.Integer.Type,
147 resulting in:
148 Failed to load interface for ‘GHC.Integer.Type’
149 There are files missing in the ‘integer-gmp’ package,
150
151 Bottom line: we make GHC.Base depend on GHC.Integer; and everything
152 else either depends on GHC.Base, or does not have NoImplicitPrelude
153 (and hence depends on Prelude).
154
155 Note [Depend on GHC.Tuple]
156 ~~~~~~~~~~~~~~~~~~~~~~~~~~
157 Similarly, tuple syntax (or ()) creates an implicit dependency on
158 GHC.Tuple, so we use the same rule as for Integer --- see Note [Depend on
159 GHC.Integer] --- to explain this to the build system. We make GHC.Base
160 depend on GHC.Tuple, and everything else depends on GHC.Base or Prelude.
161 -}
162
163 #if 0
164 -- for use when compiling GHC.Base itself doesn't work
165 data Bool = False | True
166 data Ordering = LT | EQ | GT
167 data Char = C# Char#
168 type String = [Char]
169 data Int = I# Int#
170 data () = ()
171 data [] a = MkNil
172
173 not True = False
174 (&&) True True = True
175 otherwise = True
176
177 build = error "urk"
178 foldr = error "urk"
179 #endif
180
181 -- | The 'Maybe' type encapsulates an optional value. A value of type
182 -- @'Maybe' a@ either contains a value of type @a@ (represented as @'Just' a@),
183 -- or it is empty (represented as 'Nothing'). Using 'Maybe' is a good way to
184 -- deal with errors or exceptional cases without resorting to drastic
185 -- measures such as 'error'.
186 --
187 -- The 'Maybe' type is also a monad. It is a simple kind of error
188 -- monad, where all errors are represented by 'Nothing'. A richer
189 -- error monad can be built using the 'Data.Either.Either' type.
190 --
191 data Maybe a = Nothing | Just a
192 deriving (Eq, Ord)
193
194 -- | The class of monoids (types with an associative binary operation that
195 -- has an identity). Instances should satisfy the following laws:
196 --
197 -- * @mappend mempty x = x@
198 --
199 -- * @mappend x mempty = x@
200 --
201 -- * @mappend x (mappend y z) = mappend (mappend x y) z@
202 --
203 -- * @mconcat = 'foldr' mappend mempty@
204 --
205 -- The method names refer to the monoid of lists under concatenation,
206 -- but there are many other instances.
207 --
208 -- Some types can be viewed as a monoid in more than one way,
209 -- e.g. both addition and multiplication on numbers.
210 -- In such cases we often define @newtype@s and make those instances
211 -- of 'Monoid', e.g. 'Sum' and 'Product'.
212
213 class Monoid a where
214 mempty :: a
215 -- ^ Identity of 'mappend'
216 mappend :: a -> a -> a
217 -- ^ An associative operation
218 mconcat :: [a] -> a
219
220 -- ^ Fold a list using the monoid.
221 -- For most types, the default definition for 'mconcat' will be
222 -- used, but the function is included in the class definition so
223 -- that an optimized version can be provided for specific types.
224
225 mconcat = foldr mappend mempty
226
227 instance Monoid [a] where
228 {-# INLINE mempty #-}
229 mempty = []
230 {-# INLINE mappend #-}
231 mappend = (++)
232 {-# INLINE mconcat #-}
233 mconcat xss = [x | xs <- xss, x <- xs]
234 -- See Note: [List comprehensions and inlining]
235
236 {-
237 Note: [List comprehensions and inlining]
238 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
239 The list monad operations are traditionally described in terms of concatMap:
240
241 xs >>= f = concatMap f xs
242
243 Similarly, mconcat for lists is just concat. Here in Base, however, we don't
244 have concatMap, and we'll refrain from adding it here so it won't have to be
245 hidden in imports. Instead, we use GHC's list comprehension desugaring
246 mechanism to define mconcat and the Applicative and Monad instances for lists.
247 We mark them INLINE because the inliner is not generally too keen to inline
248 build forms such as the ones these desugar to without our insistence. Defining
249 these using list comprehensions instead of foldr has an additional potential
250 benefit, as described in compiler/deSugar/DsListComp.lhs: if optimizations
251 needed to make foldr/build forms efficient are turned off, we'll get reasonably
252 efficient translations anyway.
253 -}
254
255 instance Monoid b => Monoid (a -> b) where
256 mempty _ = mempty
257 mappend f g x = f x `mappend` g x
258
259 instance Monoid () where
260 -- Should it be strict?
261 mempty = ()
262 _ `mappend` _ = ()
263 mconcat _ = ()
264
265 instance (Monoid a, Monoid b) => Monoid (a,b) where
266 mempty = (mempty, mempty)
267 (a1,b1) `mappend` (a2,b2) =
268 (a1 `mappend` a2, b1 `mappend` b2)
269
270 instance (Monoid a, Monoid b, Monoid c) => Monoid (a,b,c) where
271 mempty = (mempty, mempty, mempty)
272 (a1,b1,c1) `mappend` (a2,b2,c2) =
273 (a1 `mappend` a2, b1 `mappend` b2, c1 `mappend` c2)
274
275 instance (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a,b,c,d) where
276 mempty = (mempty, mempty, mempty, mempty)
277 (a1,b1,c1,d1) `mappend` (a2,b2,c2,d2) =
278 (a1 `mappend` a2, b1 `mappend` b2,
279 c1 `mappend` c2, d1 `mappend` d2)
280
281 instance (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) =>
282 Monoid (a,b,c,d,e) where
283 mempty = (mempty, mempty, mempty, mempty, mempty)
284 (a1,b1,c1,d1,e1) `mappend` (a2,b2,c2,d2,e2) =
285 (a1 `mappend` a2, b1 `mappend` b2, c1 `mappend` c2,
286 d1 `mappend` d2, e1 `mappend` e2)
287
288 -- lexicographical ordering
289 instance Monoid Ordering where
290 mempty = EQ
291 LT `mappend` _ = LT
292 EQ `mappend` y = y
293 GT `mappend` _ = GT
294
295 -- | Lift a semigroup into 'Maybe' forming a 'Monoid' according to
296 -- <http://en.wikipedia.org/wiki/Monoid>: \"Any semigroup @S@ may be
297 -- turned into a monoid simply by adjoining an element @e@ not in @S@
298 -- and defining @e*e = e@ and @e*s = s = s*e@ for all @s ∈ S@.\" Since
299 -- there is no \"Semigroup\" typeclass providing just 'mappend', we
300 -- use 'Monoid' instead.
301 instance Monoid a => Monoid (Maybe a) where
302 mempty = Nothing
303 Nothing `mappend` m = m
304 m `mappend` Nothing = m
305 Just m1 `mappend` Just m2 = Just (m1 `mappend` m2)
306
307 instance Monoid a => Applicative ((,) a) where
308 pure x = (mempty, x)
309 (u, f) <*> (v, x) = (u `mappend` v, f x)
310
311
312 {- | The 'Functor' class is used for types that can be mapped over.
313 Instances of 'Functor' should satisfy the following laws:
314
315 > fmap id == id
316 > fmap (f . g) == fmap f . fmap g
317
318 The instances of 'Functor' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'
319 satisfy these laws.
320 -}
321
322 class Functor f where
323 fmap :: (a -> b) -> f a -> f b
324
325 -- | Replace all locations in the input with the same value.
326 -- The default definition is @'fmap' . 'const'@, but this may be
327 -- overridden with a more efficient version.
328 (<$) :: a -> f b -> f a
329 (<$) = fmap . const
330
331 -- | A functor with application, providing operations to
332 --
333 -- * embed pure expressions ('pure'), and
334 --
335 -- * sequence computations and combine their results ('<*>').
336 --
337 -- A minimal complete definition must include implementations of these
338 -- functions satisfying the following laws:
339 --
340 -- [/identity/]
341 --
342 -- @'pure' 'id' '<*>' v = v@
343 --
344 -- [/composition/]
345 --
346 -- @'pure' (.) '<*>' u '<*>' v '<*>' w = u '<*>' (v '<*>' w)@
347 --
348 -- [/homomorphism/]
349 --
350 -- @'pure' f '<*>' 'pure' x = 'pure' (f x)@
351 --
352 -- [/interchange/]
353 --
354 -- @u '<*>' 'pure' y = 'pure' ('$' y) '<*>' u@
355 --
356 -- The other methods have the following default definitions, which may
357 -- be overridden with equivalent specialized implementations:
358 --
359 -- * @u '*>' v = 'pure' ('const' 'id') '<*>' u '<*>' v@
360 --
361 -- * @u '<*' v = 'pure' 'const' '<*>' u '<*>' v@
362 --
363 -- As a consequence of these laws, the 'Functor' instance for @f@ will satisfy
364 --
365 -- * @'fmap' f x = 'pure' f '<*>' x@
366 --
367 -- If @f@ is also a 'Monad', it should satisfy
368 --
369 -- * @'pure' = 'return'@
370 --
371 -- * @('<*>') = 'ap'@
372 --
373 -- (which implies that 'pure' and '<*>' satisfy the applicative functor laws).
374
375 class Functor f => Applicative f where
376 -- | Lift a value.
377 pure :: a -> f a
378
379 -- | Sequential application.
380 (<*>) :: f (a -> b) -> f a -> f b
381
382 -- | Sequence actions, discarding the value of the first argument.
383 (*>) :: f a -> f b -> f b
384 a1 *> a2 = (id <$ a1) <*> a2
385 -- This is essentially the same as liftA2 (const id), but if the
386 -- Functor instance has an optimized (<$), we want to use that instead.
387
388 -- | Sequence actions, discarding the value of the second argument.
389 (<*) :: f a -> f b -> f a
390 (<*) = liftA2 const
391
392 -- | A variant of '<*>' with the arguments reversed.
393 (<**>) :: Applicative f => f a -> f (a -> b) -> f b
394 (<**>) = liftA2 (flip ($))
395
396 -- | Lift a function to actions.
397 -- This function may be used as a value for `fmap` in a `Functor` instance.
398 liftA :: Applicative f => (a -> b) -> f a -> f b
399 liftA f a = pure f <*> a
400 -- Caution: since this may be used for `fmap`, we can't use the obvious
401 -- definition of liftA = fmap.
402
403 -- | Lift a binary function to actions.
404 liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
405 liftA2 f a b = fmap f a <*> b
406
407 -- | Lift a ternary function to actions.
408 liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
409 liftA3 f a b c = fmap f a <*> b <*> c
410
411
412 {-# INLINEABLE liftA #-}
413 {-# SPECIALISE liftA :: (a1->r) -> IO a1 -> IO r #-}
414 {-# SPECIALISE liftA :: (a1->r) -> Maybe a1 -> Maybe r #-}
415 {-# INLINEABLE liftA2 #-}
416 {-# SPECIALISE liftA2 :: (a1->a2->r) -> IO a1 -> IO a2 -> IO r #-}
417 {-# SPECIALISE liftA2 :: (a1->a2->r) -> Maybe a1 -> Maybe a2 -> Maybe r #-}
418 {-# INLINEABLE liftA3 #-}
419 {-# SPECIALISE liftA3 :: (a1->a2->a3->r) -> IO a1 -> IO a2 -> IO a3 -> IO r #-}
420 {-# SPECIALISE liftA3 :: (a1->a2->a3->r) ->
421 Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe r #-}
422
423 -- | The 'join' function is the conventional monad join operator. It
424 -- is used to remove one level of monadic structure, projecting its
425 -- bound argument into the outer level.
426 join :: (Monad m) => m (m a) -> m a
427 join x = x >>= id
428
429 {- | The 'Monad' class defines the basic operations over a /monad/,
430 a concept from a branch of mathematics known as /category theory/.
431 From the perspective of a Haskell programmer, however, it is best to
432 think of a monad as an /abstract datatype/ of actions.
433 Haskell's @do@ expressions provide a convenient syntax for writing
434 monadic expressions.
435
436 Instances of 'Monad' should satisfy the following laws:
437
438 * @'return' a '>>=' k = k a@
439 * @m '>>=' 'return' = m@
440 * @m '>>=' (\x -> k x '>>=' h) = (m '>>=' k) '>>=' h@
441
442 Furthermore, the 'Monad' and 'Applicative' operations should relate as follows:
443
444 * @'pure' = 'return'@
445 * @('<*>') = 'ap'@
446
447 The above laws imply:
448
449 * @'fmap' f xs = xs '>>=' 'return' . f@
450 * @('>>') = ('*>')@
451
452 and that 'pure' and ('<*>') satisfy the applicative functor laws.
453
454 The instances of 'Monad' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'
455 defined in the "Prelude" satisfy these laws.
456 -}
457 class Applicative m => Monad m where
458 -- | Sequentially compose two actions, passing any value produced
459 -- by the first as an argument to the second.
460 (>>=) :: forall a b. m a -> (a -> m b) -> m b
461
462 -- | Sequentially compose two actions, discarding any value produced
463 -- by the first, like sequencing operators (such as the semicolon)
464 -- in imperative languages.
465 (>>) :: forall a b. m a -> m b -> m b
466 m >> k = m >>= \_ -> k -- See Note [Recursive bindings for Applicative/Monad]
467 {-# INLINE (>>) #-}
468
469 -- | Inject a value into the monadic type.
470 return :: a -> m a
471
472 -- | Fail with a message. This operation is not part of the
473 -- mathematical definition of a monad, but is invoked on pattern-match
474 -- failure in a @do@ expression.
475 fail :: String -> m a
476 fail s = error s
477
478 {- Note [Recursive bindings for Applicative/Monad]
479 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
480
481 The original Applicative/Monad proposal stated that after
482 implementation, the designated implementation of (>>) would become
483
484 (>>) :: forall a b. m a -> m b -> m b
485 (>>) = (*>)
486
487 by default. You might be inclined to change this to reflect the stated
488 proposal, but you really shouldn't! Why? Because people tend to define
489 such instances the /other/ way around: in particular, it is perfectly
490 legitimate to define an instance of Applicative (*>) in terms of (>>),
491 which would lead to an infinite loop for the default implementation of
492 Monad! And people do this in the wild.
493
494 This turned into a nasty bug that was tricky to track down, and rather
495 than eliminate it everywhere upstream, it's easier to just retain the
496 original default.
497
498 -}
499
500 -- | Same as '>>=', but with the arguments interchanged.
501 {-# SPECIALISE (=<<) :: (a -> [b]) -> [a] -> [b] #-}
502 (=<<) :: Monad m => (a -> m b) -> m a -> m b
503 f =<< x = x >>= f
504
505 -- | Conditional execution of 'Applicative' expressions. For example,
506 --
507 -- > when debug (putStrLn "Debugging")
508 --
509 -- will output the string @Debugging@ if the Boolean value @debug@
510 -- is 'True', and otherwise do nothing.
511 when :: (Applicative f) => Bool -> f () -> f ()
512 {-# INLINEABLE when #-}
513 {-# SPECIALISE when :: Bool -> IO () -> IO () #-}
514 {-# SPECIALISE when :: Bool -> Maybe () -> Maybe () #-}
515 when p s = if p then s else pure ()
516
517 -- | Evaluate each action in the sequence from left to right,
518 -- and collect the results.
519 sequence :: Monad m => [m a] -> m [a]
520 {-# INLINE sequence #-}
521 sequence = mapM id
522 -- Note: [sequence and mapM]
523
524 -- | @'mapM' f@ is equivalent to @'sequence' . 'map' f@.
525 mapM :: Monad m => (a -> m b) -> [a] -> m [b]
526 {-# INLINE mapM #-}
527 mapM f as = foldr k (return []) as
528 where
529 k a r = do { x <- f a; xs <- r; return (x:xs) }
530
531 {-
532 Note: [sequence and mapM]
533 ~~~~~~~~~~~~~~~~~~~~~~~~~
534 Originally, we defined
535
536 mapM f = sequence . map f
537
538 This relied on list fusion to produce efficient code for mapM, and led to
539 excessive allocation in cryptarithm2. Defining
540
541 sequence = mapM id
542
543 relies only on inlining a tiny function (id) and beta reduction, which tends to
544 be a more reliable aspect of simplification. Indeed, this does not lead to
545 similar problems in nofib.
546 -}
547
548 -- | Promote a function to a monad.
549 liftM :: (Monad m) => (a1 -> r) -> m a1 -> m r
550 liftM f m1 = do { x1 <- m1; return (f x1) }
551
552 -- | Promote a function to a monad, scanning the monadic arguments from
553 -- left to right. For example,
554 --
555 -- > liftM2 (+) [0,1] [0,2] = [0,2,1,3]
556 -- > liftM2 (+) (Just 1) Nothing = Nothing
557 --
558 liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
559 liftM2 f m1 m2 = do { x1 <- m1; x2 <- m2; return (f x1 x2) }
560
561 -- | Promote a function to a monad, scanning the monadic arguments from
562 -- left to right (cf. 'liftM2').
563 liftM3 :: (Monad m) => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
564 liftM3 f m1 m2 m3 = do { x1 <- m1; x2 <- m2; x3 <- m3; return (f x1 x2 x3) }
565
566 -- | Promote a function to a monad, scanning the monadic arguments from
567 -- left to right (cf. 'liftM2').
568 liftM4 :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
569 liftM4 f m1 m2 m3 m4 = do { x1 <- m1; x2 <- m2; x3 <- m3; x4 <- m4; return (f x1 x2 x3 x4) }
570
571 -- | Promote a function to a monad, scanning the monadic arguments from
572 -- left to right (cf. 'liftM2').
573 liftM5 :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
574 liftM5 f m1 m2 m3 m4 m5 = do { x1 <- m1; x2 <- m2; x3 <- m3; x4 <- m4; x5 <- m5; return (f x1 x2 x3 x4 x5) }
575
576 {-# INLINEABLE liftM #-}
577 {-# SPECIALISE liftM :: (a1->r) -> IO a1 -> IO r #-}
578 {-# SPECIALISE liftM :: (a1->r) -> Maybe a1 -> Maybe r #-}
579 {-# INLINEABLE liftM2 #-}
580 {-# SPECIALISE liftM2 :: (a1->a2->r) -> IO a1 -> IO a2 -> IO r #-}
581 {-# SPECIALISE liftM2 :: (a1->a2->r) -> Maybe a1 -> Maybe a2 -> Maybe r #-}
582 {-# INLINEABLE liftM3 #-}
583 {-# SPECIALISE liftM3 :: (a1->a2->a3->r) -> IO a1 -> IO a2 -> IO a3 -> IO r #-}
584 {-# SPECIALISE liftM3 :: (a1->a2->a3->r) -> Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe r #-}
585 {-# INLINEABLE liftM4 #-}
586 {-# SPECIALISE liftM4 :: (a1->a2->a3->a4->r) -> IO a1 -> IO a2 -> IO a3 -> IO a4 -> IO r #-}
587 {-# SPECIALISE liftM4 :: (a1->a2->a3->a4->r) -> Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe a4 -> Maybe r #-}
588 {-# INLINEABLE liftM5 #-}
589 {-# SPECIALISE liftM5 :: (a1->a2->a3->a4->a5->r) -> IO a1 -> IO a2 -> IO a3 -> IO a4 -> IO a5 -> IO r #-}
590 {-# SPECIALISE liftM5 :: (a1->a2->a3->a4->a5->r) -> Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe a4 -> Maybe a5 -> Maybe r #-}
591
592 {- | In many situations, the 'liftM' operations can be replaced by uses of
593 'ap', which promotes function application.
594
595 > return f `ap` x1 `ap` ... `ap` xn
596
597 is equivalent to
598
599 > liftMn f x1 x2 ... xn
600
601 -}
602
603 ap :: (Monad m) => m (a -> b) -> m a -> m b
604 ap m1 m2 = do { x1 <- m1; x2 <- m2; return (x1 x2) }
605 -- Since many Applicative instances define (<*>) = ap, we
606 -- cannot define ap = (<*>)
607 {-# INLINEABLE ap #-}
608 {-# SPECIALISE ap :: IO (a -> b) -> IO a -> IO b #-}
609 {-# SPECIALISE ap :: Maybe (a -> b) -> Maybe a -> Maybe b #-}
610
611 -- instances for Prelude types
612
613 instance Functor ((->) r) where
614 fmap = (.)
615
616 instance Applicative ((->) a) where
617 pure = const
618 (<*>) f g x = f x (g x)
619
620 instance Monad ((->) r) where
621 return = const
622 f >>= k = \ r -> k (f r) r
623
624 instance Functor ((,) a) where
625 fmap f (x,y) = (x, f y)
626
627
628 instance Functor Maybe where
629 fmap _ Nothing = Nothing
630 fmap f (Just a) = Just (f a)
631
632 instance Applicative Maybe where
633 pure = Just
634
635 Just f <*> m = fmap f m
636 Nothing <*> _m = Nothing
637
638 Just _m1 *> m2 = m2
639 Nothing *> _m2 = Nothing
640
641 instance Monad Maybe where
642 (Just x) >>= k = k x
643 Nothing >>= _ = Nothing
644
645 (>>) = (*>)
646
647 return = Just
648 fail _ = Nothing
649
650 -- -----------------------------------------------------------------------------
651 -- The Alternative class definition
652
653 infixl 3 <|>
654
655 -- | A monoid on applicative functors.
656 --
657 -- If defined, 'some' and 'many' should be the least solutions
658 -- of the equations:
659 --
660 -- * @some v = (:) '<$>' v '<*>' many v@
661 --
662 -- * @many v = some v '<|>' 'pure' []@
663 class Applicative f => Alternative f where
664 -- | The identity of '<|>'
665 empty :: f a
666 -- | An associative binary operation
667 (<|>) :: f a -> f a -> f a
668
669 -- | One or more.
670 some :: f a -> f [a]
671 some v = some_v
672 where
673 many_v = some_v <|> pure []
674 some_v = (fmap (:) v) <*> many_v
675
676 -- | Zero or more.
677 many :: f a -> f [a]
678 many v = many_v
679 where
680 many_v = some_v <|> pure []
681 some_v = (fmap (:) v) <*> many_v
682
683
684 instance Alternative Maybe where
685 empty = Nothing
686 Nothing <|> r = r
687 l <|> _ = l
688
689 -- -----------------------------------------------------------------------------
690 -- The MonadPlus class definition
691
692 -- | Monads that also support choice and failure.
693 class (Alternative m, Monad m) => MonadPlus m where
694 -- | the identity of 'mplus'. It should also satisfy the equations
695 --
696 -- > mzero >>= f = mzero
697 -- > v >> mzero = mzero
698 --
699 mzero :: m a
700 mzero = empty
701
702 -- | an associative operation
703 mplus :: m a -> m a -> m a
704 mplus = (<|>)
705
706 instance MonadPlus Maybe
707
708 ----------------------------------------------
709 -- The list type
710
711 instance Functor [] where
712 {-# INLINE fmap #-}
713 fmap = map
714
715 -- See Note: [List comprehensions and inlining]
716 instance Applicative [] where
717 {-# INLINE pure #-}
718 pure x = [x]
719 {-# INLINE (<*>) #-}
720 fs <*> xs = [f x | f <- fs, x <- xs]
721 {-# INLINE (*>) #-}
722 xs *> ys = [y | _ <- xs, y <- ys]
723
724 -- See Note: [List comprehensions and inlining]
725 instance Monad [] where
726 {-# INLINE (>>=) #-}
727 xs >>= f = [y | x <- xs, y <- f x]
728 {-# INLINE (>>) #-}
729 (>>) = (*>)
730 {-# INLINE return #-}
731 return x = [x]
732 {-# INLINE fail #-}
733 fail _ = []
734
735 instance Alternative [] where
736 empty = []
737 (<|>) = (++)
738
739 instance MonadPlus []
740
741 {-
742 A few list functions that appear here because they are used here.
743 The rest of the prelude list functions are in GHC.List.
744 -}
745
746 ----------------------------------------------
747 -- foldr/build/augment
748 ----------------------------------------------
749
750 -- | 'foldr', applied to a binary operator, a starting value (typically
751 -- the right-identity of the operator), and a list, reduces the list
752 -- using the binary operator, from right to left:
753 --
754 -- > foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
755
756 foldr :: (a -> b -> b) -> b -> [a] -> b
757 -- foldr _ z [] = z
758 -- foldr f z (x:xs) = f x (foldr f z xs)
759 {-# INLINE [0] foldr #-}
760 -- Inline only in the final stage, after the foldr/cons rule has had a chance
761 -- Also note that we inline it when it has *two* parameters, which are the
762 -- ones we are keen about specialising!
763 foldr k z = go
764 where
765 go [] = z
766 go (y:ys) = y `k` go ys
767
768 -- | A list producer that can be fused with 'foldr'.
769 -- This function is merely
770 --
771 -- > build g = g (:) []
772 --
773 -- but GHC's simplifier will transform an expression of the form
774 -- @'foldr' k z ('build' g)@, which may arise after inlining, to @g k z@,
775 -- which avoids producing an intermediate list.
776
777 build :: forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
778 {-# INLINE [1] build #-}
779 -- The INLINE is important, even though build is tiny,
780 -- because it prevents [] getting inlined in the version that
781 -- appears in the interface file. If [] *is* inlined, it
782 -- won't match with [] appearing in rules in an importing module.
783 --
784 -- The "1" says to inline in phase 1
785
786 build g = g (:) []
787
788 -- | A list producer that can be fused with 'foldr'.
789 -- This function is merely
790 --
791 -- > augment g xs = g (:) xs
792 --
793 -- but GHC's simplifier will transform an expression of the form
794 -- @'foldr' k z ('augment' g xs)@, which may arise after inlining, to
795 -- @g k ('foldr' k z xs)@, which avoids producing an intermediate list.
796
797 augment :: forall a. (forall b. (a->b->b) -> b -> b) -> [a] -> [a]
798 {-# INLINE [1] augment #-}
799 augment g xs = g (:) xs
800
801 {-# RULES
802 "fold/build" forall k z (g::forall b. (a->b->b) -> b -> b) .
803 foldr k z (build g) = g k z
804
805 "foldr/augment" forall k z xs (g::forall b. (a->b->b) -> b -> b) .
806 foldr k z (augment g xs) = g k (foldr k z xs)
807
808 "foldr/id" foldr (:) [] = \x -> x
809 "foldr/app" [1] forall ys. foldr (:) ys = \xs -> xs ++ ys
810 -- Only activate this from phase 1, because that's
811 -- when we disable the rule that expands (++) into foldr
812
813 -- The foldr/cons rule looks nice, but it can give disastrously
814 -- bloated code when commpiling
815 -- array (a,b) [(1,2), (2,2), (3,2), ...very long list... ]
816 -- i.e. when there are very very long literal lists
817 -- So I've disabled it for now. We could have special cases
818 -- for short lists, I suppose.
819 -- "foldr/cons" forall k z x xs. foldr k z (x:xs) = k x (foldr k z xs)
820
821 "foldr/single" forall k z x. foldr k z [x] = k x z
822 "foldr/nil" forall k z. foldr k z [] = z
823
824 "foldr/cons/build" forall k z x (g::forall b. (a->b->b) -> b -> b) .
825 foldr k z (x:build g) = k x (g k z)
826
827 "augment/build" forall (g::forall b. (a->b->b) -> b -> b)
828 (h::forall b. (a->b->b) -> b -> b) .
829 augment g (build h) = build (\c n -> g c (h c n))
830 "augment/nil" forall (g::forall b. (a->b->b) -> b -> b) .
831 augment g [] = build g
832 #-}
833
834 -- This rule is true, but not (I think) useful:
835 -- augment g (augment h t) = augment (\cn -> g c (h c n)) t
836
837 ----------------------------------------------
838 -- map
839 ----------------------------------------------
840
841 -- | 'map' @f xs@ is the list obtained by applying @f@ to each element
842 -- of @xs@, i.e.,
843 --
844 -- > map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
845 -- > map f [x1, x2, ...] == [f x1, f x2, ...]
846
847 map :: (a -> b) -> [a] -> [b]
848 {-# NOINLINE [1] map #-} -- We want the RULE to fire first.
849 -- It's recursive, so won't inline anyway,
850 -- but saying so is more explicit
851 map _ [] = []
852 map f (x:xs) = f x : map f xs
853
854 -- Note eta expanded
855 mapFB :: (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst
856 {-# INLINE [0] mapFB #-}
857 mapFB c f = \x ys -> c (f x) ys
858
859 -- The rules for map work like this.
860 --
861 -- Up to (but not including) phase 1, we use the "map" rule to
862 -- rewrite all saturated applications of map with its build/fold
863 -- form, hoping for fusion to happen.
864 -- In phase 1 and 0, we switch off that rule, inline build, and
865 -- switch on the "mapList" rule, which rewrites the foldr/mapFB
866 -- thing back into plain map.
867 --
868 -- It's important that these two rules aren't both active at once
869 -- (along with build's unfolding) else we'd get an infinite loop
870 -- in the rules. Hence the activation control below.
871 --
872 -- The "mapFB" rule optimises compositions of map.
873 --
874 -- This same pattern is followed by many other functions:
875 -- e.g. append, filter, iterate, repeat, etc.
876
877 {-# RULES
878 "map" [~1] forall f xs. map f xs = build (\c n -> foldr (mapFB c f) n xs)
879 "mapList" [1] forall f. foldr (mapFB (:) f) [] = map f
880 "mapFB" forall c f g. mapFB (mapFB c f) g = mapFB c (f.g)
881 #-}
882
883 -- See Breitner, Eisenberg, Peyton Jones, and Weirich, "Safe Zero-cost
884 -- Coercions for Haskell", section 6.5:
885 -- http://research.microsoft.com/en-us/um/people/simonpj/papers/ext-f/coercible.pdf
886
887 {-# RULES "map/coerce" [1] map coerce = coerce #-}
888
889
890 ----------------------------------------------
891 -- append
892 ----------------------------------------------
893
894 -- | Append two lists, i.e.,
895 --
896 -- > [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
897 -- > [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
898 --
899 -- If the first list is not finite, the result is the first list.
900
901 (++) :: [a] -> [a] -> [a]
902 {-# NOINLINE [1] (++) #-} -- We want the RULE to fire first.
903 -- It's recursive, so won't inline anyway,
904 -- but saying so is more explicit
905 (++) [] ys = ys
906 (++) (x:xs) ys = x : xs ++ ys
907
908 {-# RULES
909 "++" [~1] forall xs ys. xs ++ ys = augment (\c n -> foldr c n xs) ys
910 #-}
911
912
913 -- |'otherwise' is defined as the value 'True'. It helps to make
914 -- guards more readable. eg.
915 --
916 -- > f x | x < 0 = ...
917 -- > | otherwise = ...
918 otherwise :: Bool
919 otherwise = True
920
921 ----------------------------------------------
922 -- Type Char and String
923 ----------------------------------------------
924
925 -- | A 'String' is a list of characters. String constants in Haskell are values
926 -- of type 'String'.
927 --
928 type String = [Char]
929
930 unsafeChr :: Int -> Char
931 unsafeChr (I# i#) = C# (chr# i#)
932
933 -- | The 'Prelude.fromEnum' method restricted to the type 'Data.Char.Char'.
934 ord :: Char -> Int
935 ord (C# c#) = I# (ord# c#)
936
937 -- | This 'String' equality predicate is used when desugaring
938 -- pattern-matches against strings.
939 eqString :: String -> String -> Bool
940 eqString [] [] = True
941 eqString (c1:cs1) (c2:cs2) = c1 == c2 && cs1 `eqString` cs2
942 eqString _ _ = False
943
944 {-# RULES "eqString" (==) = eqString #-}
945 -- eqString also has a BuiltInRule in PrelRules.lhs:
946 -- eqString (unpackCString# (Lit s1)) (unpackCString# (Lit s2) = s1==s2
947
948
949 ----------------------------------------------
950 -- 'Int' related definitions
951 ----------------------------------------------
952
953 maxInt, minInt :: Int
954
955 {- Seems clumsy. Should perhaps put minInt and MaxInt directly into MachDeps.h -}
956 #if WORD_SIZE_IN_BITS == 31
957 minInt = I# (-0x40000000#)
958 maxInt = I# 0x3FFFFFFF#
959 #elif WORD_SIZE_IN_BITS == 32
960 minInt = I# (-0x80000000#)
961 maxInt = I# 0x7FFFFFFF#
962 #else
963 minInt = I# (-0x8000000000000000#)
964 maxInt = I# 0x7FFFFFFFFFFFFFFF#
965 #endif
966
967 ----------------------------------------------
968 -- The function type
969 ----------------------------------------------
970
971 -- | Identity function.
972 id :: a -> a
973 id x = x
974
975 -- Assertion function. This simply ignores its boolean argument.
976 -- The compiler may rewrite it to @('assertError' line)@.
977
978 -- | If the first argument evaluates to 'True', then the result is the
979 -- second argument. Otherwise an 'AssertionFailed' exception is raised,
980 -- containing a 'String' with the source file and line number of the
981 -- call to 'assert'.
982 --
983 -- Assertions can normally be turned on or off with a compiler flag
984 -- (for GHC, assertions are normally on unless optimisation is turned on
985 -- with @-O@ or the @-fignore-asserts@
986 -- option is given). When assertions are turned off, the first
987 -- argument to 'assert' is ignored, and the second argument is
988 -- returned as the result.
989
990 -- SLPJ: in 5.04 etc 'assert' is in GHC.Prim,
991 -- but from Template Haskell onwards it's simply
992 -- defined here in Base.lhs
993 assert :: Bool -> a -> a
994 assert _pred r = r
995
996 breakpoint :: a -> a
997 breakpoint r = r
998
999 breakpointCond :: Bool -> a -> a
1000 breakpointCond _ r = r
1001
1002 data Opaque = forall a. O a
1003
1004 -- | Constant function.
1005 const :: a -> b -> a
1006 const x _ = x
1007
1008 -- | Function composition.
1009 {-# INLINE (.) #-}
1010 -- Make sure it has TWO args only on the left, so that it inlines
1011 -- when applied to two functions, even if there is no final argument
1012 (.) :: (b -> c) -> (a -> b) -> a -> c
1013 (.) f g = \x -> f (g x)
1014
1015 -- | @'flip' f@ takes its (first) two arguments in the reverse order of @f@.
1016 flip :: (a -> b -> c) -> b -> a -> c
1017 flip f x y = f y x
1018
1019 -- | Application operator. This operator is redundant, since ordinary
1020 -- application @(f x)@ means the same as @(f '$' x)@. However, '$' has
1021 -- low, right-associative binding precedence, so it sometimes allows
1022 -- parentheses to be omitted; for example:
1023 --
1024 -- > f $ g $ h x = f (g (h x))
1025 --
1026 -- It is also useful in higher-order situations, such as @'map' ('$' 0) xs@,
1027 -- or @'Data.List.zipWith' ('$') fs xs@.
1028 {-# INLINE ($) #-}
1029 ($) :: (a -> b) -> a -> b
1030 f $ x = f x
1031
1032 -- | Strict (call-by-value) application operator. It takes a function and an
1033 -- argument, evaluates the argument to weak head normal form (WHNF), then calls
1034 -- the function with that value.
1035
1036 ($!) :: (a -> b) -> a -> b
1037 f $! x = let !vx = x in f vx -- see #2273
1038
1039 -- | @'until' p f@ yields the result of applying @f@ until @p@ holds.
1040 until :: (a -> Bool) -> (a -> a) -> a -> a
1041 until p f = go
1042 where
1043 go x | p x = x
1044 | otherwise = go (f x)
1045
1046 -- | 'asTypeOf' is a type-restricted version of 'const'. It is usually
1047 -- used as an infix operator, and its typing forces its first argument
1048 -- (which is usually overloaded) to have the same type as the second.
1049 asTypeOf :: a -> a -> a
1050 asTypeOf = const
1051
1052 ----------------------------------------------
1053 -- Functor/Applicative/Monad instances for IO
1054 ----------------------------------------------
1055
1056 instance Functor IO where
1057 fmap f x = x >>= (return . f)
1058
1059 instance Applicative IO where
1060 pure = return
1061 (<*>) = ap
1062
1063 instance Monad IO where
1064 {-# INLINE return #-}
1065 {-# INLINE (>>) #-}
1066 {-# INLINE (>>=) #-}
1067 m >> k = m >>= \ _ -> k
1068 return = returnIO
1069 (>>=) = bindIO
1070 fail s = failIO s
1071
1072 returnIO :: a -> IO a
1073 returnIO x = IO $ \ s -> (# s, x #)
1074
1075 bindIO :: IO a -> (a -> IO b) -> IO b
1076 bindIO (IO m) k = IO $ \ s -> case m s of (# new_s, a #) -> unIO (k a) new_s
1077
1078 thenIO :: IO a -> IO b -> IO b
1079 thenIO (IO m) k = IO $ \ s -> case m s of (# new_s, _ #) -> unIO k new_s
1080
1081 unIO :: IO a -> (State# RealWorld -> (# State# RealWorld, a #))
1082 unIO (IO a) = a
1083
1084 {- |
1085 Returns the 'tag' of a constructor application; this function is used
1086 by the deriving code for Eq, Ord and Enum.
1087
1088 The primitive dataToTag# requires an evaluated constructor application
1089 as its argument, so we provide getTag as a wrapper that performs the
1090 evaluation before calling dataToTag#. We could have dataToTag#
1091 evaluate its argument, but we prefer to do it this way because (a)
1092 dataToTag# can be an inline primop if it doesn't need to do any
1093 evaluation, and (b) we want to expose the evaluation to the
1094 simplifier, because it might be possible to eliminate the evaluation
1095 in the case when the argument is already known to be evaluated.
1096 -}
1097 {-# INLINE getTag #-}
1098 getTag :: a -> Int#
1099 getTag !x = dataToTag# x
1100
1101 ----------------------------------------------
1102 -- Numeric primops
1103 ----------------------------------------------
1104
1105 -- Definitions of the boxed PrimOps; these will be
1106 -- used in the case of partial applications, etc.
1107
1108 {-# INLINE quotInt #-}
1109 {-# INLINE remInt #-}
1110
1111 quotInt, remInt, divInt, modInt :: Int -> Int -> Int
1112 (I# x) `quotInt` (I# y) = I# (x `quotInt#` y)
1113 (I# x) `remInt` (I# y) = I# (x `remInt#` y)
1114 (I# x) `divInt` (I# y) = I# (x `divInt#` y)
1115 (I# x) `modInt` (I# y) = I# (x `modInt#` y)
1116
1117 quotRemInt :: Int -> Int -> (Int, Int)
1118 (I# x) `quotRemInt` (I# y) = case x `quotRemInt#` y of
1119 (# q, r #) ->
1120 (I# q, I# r)
1121
1122 divModInt :: Int -> Int -> (Int, Int)
1123 (I# x) `divModInt` (I# y) = case x `divModInt#` y of
1124 (# q, r #) -> (I# q, I# r)
1125
1126 divModInt# :: Int# -> Int# -> (# Int#, Int# #)
1127 x# `divModInt#` y#
1128 | isTrue# (x# ># 0#) && isTrue# (y# <# 0#) =
1129 case (x# -# 1#) `quotRemInt#` y# of
1130 (# q, r #) -> (# q -# 1#, r +# y# +# 1# #)
1131 | isTrue# (x# <# 0#) && isTrue# (y# ># 0#) =
1132 case (x# +# 1#) `quotRemInt#` y# of
1133 (# q, r #) -> (# q -# 1#, r +# y# -# 1# #)
1134 | otherwise =
1135 x# `quotRemInt#` y#
1136
1137 -- Wrappers for the shift operations. The uncheckedShift# family are
1138 -- undefined when the amount being shifted by is greater than the size
1139 -- in bits of Int#, so these wrappers perform a check and return
1140 -- either zero or -1 appropriately.
1141 --
1142 -- Note that these wrappers still produce undefined results when the
1143 -- second argument (the shift amount) is negative.
1144
1145 -- | Shift the argument left by the specified number of bits
1146 -- (which must be non-negative).
1147 shiftL# :: Word# -> Int# -> Word#
1148 a `shiftL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0##
1149 | otherwise = a `uncheckedShiftL#` b
1150
1151 -- | Shift the argument right by the specified number of bits
1152 -- (which must be non-negative).
1153 -- The "RL" means "right, logical" (as opposed to RA for arithmetic)
1154 -- (although an arithmetic right shift wouldn't make sense for Word#)
1155 shiftRL# :: Word# -> Int# -> Word#
1156 a `shiftRL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0##
1157 | otherwise = a `uncheckedShiftRL#` b
1158
1159 -- | Shift the argument left by the specified number of bits
1160 -- (which must be non-negative).
1161 iShiftL# :: Int# -> Int# -> Int#
1162 a `iShiftL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0#
1163 | otherwise = a `uncheckedIShiftL#` b
1164
1165 -- | Shift the argument right (signed) by the specified number of bits
1166 -- (which must be non-negative).
1167 -- The "RA" means "right, arithmetic" (as opposed to RL for logical)
1168 iShiftRA# :: Int# -> Int# -> Int#
1169 a `iShiftRA#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = if isTrue# (a <# 0#)
1170 then (-1#)
1171 else 0#
1172 | otherwise = a `uncheckedIShiftRA#` b
1173
1174 -- | Shift the argument right (unsigned) by the specified number of bits
1175 -- (which must be non-negative).
1176 -- The "RL" means "right, logical" (as opposed to RA for arithmetic)
1177 iShiftRL# :: Int# -> Int# -> Int#
1178 a `iShiftRL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0#
1179 | otherwise = a `uncheckedIShiftRL#` b
1180
1181 -- Rules for C strings (the functions themselves are now in GHC.CString)
1182 {-# RULES
1183 "unpack" [~1] forall a . unpackCString# a = build (unpackFoldrCString# a)
1184 "unpack-list" [1] forall a . unpackFoldrCString# a (:) [] = unpackCString# a
1185 "unpack-append" forall a n . unpackFoldrCString# a (:) n = unpackAppendCString# a n
1186
1187 -- There's a built-in rule (in PrelRules.lhs) for
1188 -- unpackFoldr "foo" c (unpackFoldr "baz" c n) = unpackFoldr "foobaz" c n
1189
1190 #-}
1191
1192
1193 #ifdef __HADDOCK__
1194 -- | A special argument for the 'Control.Monad.ST.ST' type constructor,
1195 -- indexing a state embedded in the 'Prelude.IO' monad by
1196 -- 'Control.Monad.ST.stToIO'.
1197 data RealWorld
1198 #endif