1 \section[GHC.Base]{Module @GHC.Base@}
3 The overall structure of the GHC Prelude is a bit tricky.
5 a) We want to avoid "orphan modules", i.e. ones with instance
6 decls that don't belong either to a tycon or a class
7 defined in the same module
9 b) We want to avoid giant modules
11 So the rough structure is as follows, in (linearised) dependency order
14 GHC.Prim Has no implementation. It defines built-in things, and
15 by importing it you bring them into scope.
16 The source file is GHC.Prim.hi-boot, which is just
17 copied to make GHC.Prim.hi
19 GHC.Base Classes: Eq, Ord, Functor, Monad
20 Types: list, (), Int, Bool, Ordering, Char, String
22 Data.Tuple Types: tuples, plus instances for GHC.Base classes
24 GHC.Show Class: Show, plus instances for GHC.Base/GHC.Tup types
26 GHC.Enum Class: Enum, plus instances for GHC.Base/GHC.Tup types
28 Data.Maybe Type: Maybe, plus instances for GHC.Base classes
30 GHC.List List functions
32 GHC.Num Class: Num, plus instances for Int
33 Type: Integer, plus instances for all classes so far (Eq, Ord, Num, Show)
35 Integer is needed here because it is mentioned in the signature
36 of 'fromInteger' in class Num
38 GHC.Real Classes: Real, Integral, Fractional, RealFrac
39 plus instances for Int, Integer
40 Types: Ratio, Rational
41 plus intances for classes so far
43 Rational is needed here because it is mentioned in the signature
44 of 'toRational' in class Real
46 GHC.ST The ST monad, instances and a few helper functions
48 Ix Classes: Ix, plus instances for Int, Bool, Char, Integer, Ordering, tuples
50 GHC.Arr Types: Array, MutableArray, MutableVar
52 Arrays are used by a function in GHC.Float
54 GHC.Float Classes: Floating, RealFloat
55 Types: Float, Double, plus instances of all classes so far
57 This module contains everything to do with floating point.
58 It is a big module (900 lines)
59 With a bit of luck, many modules can be compiled without ever reading GHC.Float.hi
62 Other Prelude modules are much easier with fewer complex dependencies.
71 , ExistentialQuantification
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 #-}
79 -----------------------------------------------------------------------------
82 -- Copyright : (c) The University of Glasgow, 1992-2002
83 -- License : see libraries/base/LICENSE
85 -- Maintainer : cvs-ghc@haskell.org
86 -- Stability : internal
87 -- Portability : non-portable (GHC extensions)
89 -- Basic data types and classes.
91 -----------------------------------------------------------------------------
101 --module GHC.Generics, -- JPM: We no longer export GHC.Generics
102 -- by default to avoid name clashes
105 module GHC.Prim, -- Re-export GHC.Prim and GHC.Err, to avoid lots
106 module GHC.Err -- of people having to import it explicitly
113 -- JPM: Since we don't export it, we don't need to import GHC.Generics
114 --import GHC.Generics
117 import {-# SOURCE #-} GHC.Show
118 import {-# SOURCE #-} GHC.Err
119 import {-# SOURCE #-} GHC.IO (failIO)
121 -- These two are not strictly speaking required by this module, but they are
122 -- implicit dependencies whenever () or tuples are mentioned, so adding them
123 -- as imports here helps to get the dependencies right in the new build system.
133 default () -- Double isn't available yet
137 %*********************************************************
139 \subsection{DEBUGGING STUFF}
140 %* (for use when compiling GHC.Base itself doesn't work)
142 %*********************************************************
146 data Bool = False | True
147 data Ordering = LT | EQ | GT
155 (&&) True True = True
164 %*********************************************************
166 \subsection{Monadic classes @Functor@, @Monad@ }
168 %*********************************************************
171 {- | The 'Functor' class is used for types that can be mapped over.
172 Instances of 'Functor' should satisfy the following laws:
175 > fmap (f . g) == fmap f . fmap g
177 The instances of 'Functor' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'
181 class Functor f where
182 fmap :: (a -> b) -> f a -> f b
184 -- | Replace all locations in the input with the same value.
185 -- The default definition is @'fmap' . 'const'@, but this may be
186 -- overridden with a more efficient version.
187 (<$) :: a -> f b -> f a
190 {- | The 'Monad' class defines the basic operations over a /monad/,
191 a concept from a branch of mathematics known as /category theory/.
192 From the perspective of a Haskell programmer, however, it is best to
193 think of a monad as an /abstract datatype/ of actions.
194 Haskell's @do@ expressions provide a convenient syntax for writing
197 Minimal complete definition: '>>=' and 'return'.
199 Instances of 'Monad' should satisfy the following laws:
201 > return a >>= k == k a
203 > m >>= (\x -> k x >>= h) == (m >>= k) >>= h
205 Instances of both 'Monad' and 'Functor' should additionally satisfy the law:
207 > fmap f xs == xs >>= return . f
209 The instances of 'Monad' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'
210 defined in the "Prelude" satisfy these laws.
214 -- | Sequentially compose two actions, passing any value produced
215 -- by the first as an argument to the second.
216 (>>=) :: forall a b. m a -> (a -> m b) -> m b
217 -- | Sequentially compose two actions, discarding any value produced
218 -- by the first, like sequencing operators (such as the semicolon)
219 -- in imperative languages.
220 (>>) :: forall a b. m a -> m b -> m b
221 -- Explicit for-alls so that we know what order to
222 -- give type arguments when desugaring
224 -- | Inject a value into the monadic type.
226 -- | Fail with a message. This operation is not part of the
227 -- mathematical definition of a monad, but is invoked on pattern-match
228 -- failure in a @do@ expression.
229 fail :: String -> m a
232 m >> k = m >>= \_ -> k
237 %*********************************************************
239 \subsection{The list type}
241 %*********************************************************
244 instance Functor [] where
247 instance Monad [] where
248 m >>= k = foldr ((++) . k) [] m
249 m >> k = foldr ((++) . (\ _ -> k)) [] m
254 A few list functions that appear here because they are used here.
255 The rest of the prelude list functions are in GHC.List.
257 ----------------------------------------------
258 -- foldr/build/augment
259 ----------------------------------------------
262 -- | 'foldr', applied to a binary operator, a starting value (typically
263 -- the right-identity of the operator), and a list, reduces the list
264 -- using the binary operator, from right to left:
266 -- > foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
268 foldr :: (a -> b -> b) -> b -> [a] -> b
270 -- foldr f z (x:xs) = f x (foldr f z xs)
271 {-# INLINE [0] foldr #-}
272 -- Inline only in the final stage, after the foldr/cons rule has had a chance
273 -- Also note that we inline it when it has *two* parameters, which are the
274 -- ones we are keen about specialising!
278 go (y:ys) = y `k` go ys
280 -- | A list producer that can be fused with 'foldr'.
281 -- This function is merely
283 -- > build g = g (:) []
285 -- but GHC's simplifier will transform an expression of the form
286 -- @'foldr' k z ('build' g)@, which may arise after inlining, to @g k z@,
287 -- which avoids producing an intermediate list.
289 build :: forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
290 {-# INLINE [1] build #-}
291 -- The INLINE is important, even though build is tiny,
292 -- because it prevents [] getting inlined in the version that
293 -- appears in the interface file. If [] *is* inlined, it
294 -- won't match with [] appearing in rules in an importing module.
296 -- The "1" says to inline in phase 1
300 -- | A list producer that can be fused with 'foldr'.
301 -- This function is merely
303 -- > augment g xs = g (:) xs
305 -- but GHC's simplifier will transform an expression of the form
306 -- @'foldr' k z ('augment' g xs)@, which may arise after inlining, to
307 -- @g k ('foldr' k z xs)@, which avoids producing an intermediate list.
309 augment :: forall a. (forall b. (a->b->b) -> b -> b) -> [a] -> [a]
310 {-# INLINE [1] augment #-}
311 augment g xs = g (:) xs
314 "fold/build" forall k z (g::forall b. (a->b->b) -> b -> b) .
315 foldr k z (build g) = g k z
317 "foldr/augment" forall k z xs (g::forall b. (a->b->b) -> b -> b) .
318 foldr k z (augment g xs) = g k (foldr k z xs)
320 "foldr/id" foldr (:) [] = \x -> x
321 "foldr/app" [1] forall ys. foldr (:) ys = \xs -> xs ++ ys
322 -- Only activate this from phase 1, because that's
323 -- when we disable the rule that expands (++) into foldr
325 -- The foldr/cons rule looks nice, but it can give disastrously
326 -- bloated code when commpiling
327 -- array (a,b) [(1,2), (2,2), (3,2), ...very long list... ]
328 -- i.e. when there are very very long literal lists
329 -- So I've disabled it for now. We could have special cases
330 -- for short lists, I suppose.
331 -- "foldr/cons" forall k z x xs. foldr k z (x:xs) = k x (foldr k z xs)
333 "foldr/single" forall k z x. foldr k z [x] = k x z
334 "foldr/nil" forall k z. foldr k z [] = z
336 "augment/build" forall (g::forall b. (a->b->b) -> b -> b)
337 (h::forall b. (a->b->b) -> b -> b) .
338 augment g (build h) = build (\c n -> g c (h c n))
339 "augment/nil" forall (g::forall b. (a->b->b) -> b -> b) .
340 augment g [] = build g
343 -- This rule is true, but not (I think) useful:
344 -- augment g (augment h t) = augment (\cn -> g c (h c n)) t
348 ----------------------------------------------
350 ----------------------------------------------
353 -- | 'map' @f xs@ is the list obtained by applying @f@ to each element
356 -- > map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
357 -- > map f [x1, x2, ...] == [f x1, f x2, ...]
359 map :: (a -> b) -> [a] -> [b]
361 map f (x:xs) = f x : map f xs
364 mapFB :: (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst
365 {-# INLINE [0] mapFB #-}
366 mapFB c f = \x ys -> c (f x) ys
368 -- The rules for map work like this.
370 -- Up to (but not including) phase 1, we use the "map" rule to
371 -- rewrite all saturated applications of map with its build/fold
372 -- form, hoping for fusion to happen.
373 -- In phase 1 and 0, we switch off that rule, inline build, and
374 -- switch on the "mapList" rule, which rewrites the foldr/mapFB
375 -- thing back into plain map.
377 -- It's important that these two rules aren't both active at once
378 -- (along with build's unfolding) else we'd get an infinite loop
379 -- in the rules. Hence the activation control below.
381 -- The "mapFB" rule optimises compositions of map.
383 -- This same pattern is followed by many other functions:
384 -- e.g. append, filter, iterate, repeat, etc.
387 "map" [~1] forall f xs. map f xs = build (\c n -> foldr (mapFB c f) n xs)
388 "mapList" [1] forall f. foldr (mapFB (:) f) [] = map f
389 "mapFB" forall c f g. mapFB (mapFB c f) g = mapFB c (f.g)
394 ----------------------------------------------
396 ----------------------------------------------
398 -- | Append two lists, i.e.,
400 -- > [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
401 -- > [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
403 -- If the first list is not finite, the result is the first list.
405 (++) :: [a] -> [a] -> [a]
407 (++) (x:xs) ys = x : xs ++ ys
410 "++" [~1] forall xs ys. xs ++ ys = augment (\c n -> foldr c n xs) ys
416 %*********************************************************
418 \subsection{Type @Bool@}
420 %*********************************************************
423 -- |'otherwise' is defined as the value 'True'. It helps to make
424 -- guards more readable. eg.
426 -- > f x | x < 0 = ...
427 -- > | otherwise = ...
432 %*********************************************************
434 \subsection{Type @Char@ and @String@}
436 %*********************************************************
439 -- | A 'String' is a list of characters. String constants in Haskell are values
445 "x# `eqChar#` x#" forall x#. x# `eqChar#` x# = True
446 "x# `neChar#` x#" forall x#. x# `neChar#` x# = False
447 "x# `gtChar#` x#" forall x#. x# `gtChar#` x# = False
448 "x# `geChar#` x#" forall x#. x# `geChar#` x# = True
449 "x# `leChar#` x#" forall x#. x# `leChar#` x# = True
450 "x# `ltChar#` x#" forall x#. x# `ltChar#` x# = False
453 -- | The 'Prelude.toEnum' method restricted to the type 'Data.Char.Char'.
456 | int2Word# i# `leWord#` int2Word# 0x10FFFF# = C# (chr# i#)
458 = error ("Prelude.chr: bad argument: " ++ showSignedInt (I# 9#) i "")
460 unsafeChr :: Int -> Char
461 unsafeChr (I# i#) = C# (chr# i#)
463 -- | The 'Prelude.fromEnum' method restricted to the type 'Data.Char.Char'.
465 ord (C# c#) = I# (ord# c#)
468 String equality is used when desugaring pattern-matches against strings.
471 eqString :: String -> String -> Bool
472 eqString [] [] = True
473 eqString (c1:cs1) (c2:cs2) = c1 == c2 && cs1 `eqString` cs2
476 {-# RULES "eqString" (==) = eqString #-}
477 -- eqString also has a BuiltInRule in PrelRules.lhs:
478 -- eqString (unpackCString# (Lit s1)) (unpackCString# (Lit s2) = s1==s2
482 %*********************************************************
484 \subsection{Type @Int@}
486 %*********************************************************
489 zeroInt, oneInt, twoInt, maxInt, minInt :: Int
494 {- Seems clumsy. Should perhaps put minInt and MaxInt directly into MachDeps.h -}
495 #if WORD_SIZE_IN_BITS == 31
496 minInt = I# (-0x40000000#)
497 maxInt = I# 0x3FFFFFFF#
498 #elif WORD_SIZE_IN_BITS == 32
499 minInt = I# (-0x80000000#)
500 maxInt = I# 0x7FFFFFFF#
502 minInt = I# (-0x8000000000000000#)
503 maxInt = I# 0x7FFFFFFFFFFFFFFF#
508 %*********************************************************
510 \subsection{The function type}
512 %*********************************************************
515 -- | Identity function.
519 -- | The call '(lazy e)' means the same as 'e', but 'lazy' has a
520 -- magical strictness property: it is lazy in its first argument,
521 -- even though its semantics is strict.
524 -- Implementation note: its strictness and unfolding are over-ridden
525 -- by the definition in MkId.lhs; in both cases to nothing at all.
526 -- That way, 'lazy' does not get inlined, and the strictness analyser
527 -- sees it as lazy. Then the worker/wrapper phase inlines it.
530 -- Assertion function. This simply ignores its boolean argument.
531 -- The compiler may rewrite it to @('assertError' line)@.
533 -- | If the first argument evaluates to 'True', then the result is the
534 -- second argument. Otherwise an 'AssertionFailed' exception is raised,
535 -- containing a 'String' with the source file and line number of the
538 -- Assertions can normally be turned on or off with a compiler flag
539 -- (for GHC, assertions are normally on unless optimisation is turned on
540 -- with @-O@ or the @-fignore-asserts@
541 -- option is given). When assertions are turned off, the first
542 -- argument to 'assert' is ignored, and the second argument is
543 -- returned as the result.
545 -- SLPJ: in 5.04 etc 'assert' is in GHC.Prim,
546 -- but from Template Haskell onwards it's simply
547 -- defined here in Base.lhs
548 assert :: Bool -> a -> a
554 breakpointCond :: Bool -> a -> a
555 breakpointCond _ r = r
557 data Opaque = forall a. O a
559 -- | Constant function.
563 -- | Function composition.
565 -- Make sure it has TWO args only on the left, so that it inlines
566 -- when applied to two functions, even if there is no final argument
567 (.) :: (b -> c) -> (a -> b) -> a -> c
568 (.) f g = \x -> f (g x)
570 -- | @'flip' f@ takes its (first) two arguments in the reverse order of @f@.
571 flip :: (a -> b -> c) -> b -> a -> c
574 -- | Application operator. This operator is redundant, since ordinary
575 -- application @(f x)@ means the same as @(f '$' x)@. However, '$' has
576 -- low, right-associative binding precedence, so it sometimes allows
577 -- parentheses to be omitted; for example:
579 -- > f $ g $ h x = f (g (h x))
581 -- It is also useful in higher-order situations, such as @'map' ('$' 0) xs@,
582 -- or @'Data.List.zipWith' ('$') fs xs@.
584 ($) :: (a -> b) -> a -> b
587 -- | @'until' p f@ yields the result of applying @f@ until @p@ holds.
588 until :: (a -> Bool) -> (a -> a) -> a -> a
589 until p f x | p x = x
590 | otherwise = until p f (f x)
592 -- | 'asTypeOf' is a type-restricted version of 'const'. It is usually
593 -- used as an infix operator, and its typing forces its first argument
594 -- (which is usually overloaded) to have the same type as the second.
595 asTypeOf :: a -> a -> a
599 %*********************************************************
601 \subsection{@Functor@ and @Monad@ instances for @IO@}
603 %*********************************************************
606 instance Functor IO where
607 fmap f x = x >>= (return . f)
609 instance Monad IO where
610 {-# INLINE return #-}
613 m >> k = m >>= \ _ -> k
616 fail s = GHC.IO.failIO s
618 returnIO :: a -> IO a
619 returnIO x = IO $ \ s -> (# s, x #)
621 bindIO :: IO a -> (a -> IO b) -> IO b
622 bindIO (IO m) k = IO $ \ s -> case m s of (# new_s, a #) -> unIO (k a) new_s
624 thenIO :: IO a -> IO b -> IO b
625 thenIO (IO m) k = IO $ \ s -> case m s of (# new_s, _ #) -> unIO k new_s
627 unIO :: IO a -> (State# RealWorld -> (# State# RealWorld, a #))
631 %*********************************************************
633 \subsection{@getTag@}
635 %*********************************************************
637 Returns the 'tag' of a constructor application; this function is used
638 by the deriving code for Eq, Ord and Enum.
640 The primitive dataToTag# requires an evaluated constructor application
641 as its argument, so we provide getTag as a wrapper that performs the
642 evaluation before calling dataToTag#. We could have dataToTag#
643 evaluate its argument, but we prefer to do it this way because (a)
644 dataToTag# can be an inline primop if it doesn't need to do any
645 evaluation, and (b) we want to expose the evaluation to the
646 simplifier, because it might be possible to eliminate the evaluation
647 in the case when the argument is already known to be evaluated.
650 {-# INLINE getTag #-}
652 getTag x = x `seq` dataToTag# x
655 %*********************************************************
657 \subsection{Numeric primops}
659 %*********************************************************
662 divInt# :: Int# -> Int# -> Int#
664 -- Be careful NOT to overflow if we do any additional arithmetic
665 -- on the arguments... the following previous version of this
666 -- code has problems with overflow:
667 -- | (x# ># 0#) && (y# <# 0#) = ((x# -# y#) -# 1#) `quotInt#` y#
668 -- | (x# <# 0#) && (y# ># 0#) = ((x# -# y#) +# 1#) `quotInt#` y#
669 | (x# ># 0#) && (y# <# 0#) = ((x# -# 1#) `quotInt#` y#) -# 1#
670 | (x# <# 0#) && (y# ># 0#) = ((x# +# 1#) `quotInt#` y#) -# 1#
671 | otherwise = x# `quotInt#` y#
673 modInt# :: Int# -> Int# -> Int#
675 | (x# ># 0#) && (y# <# 0#) ||
676 (x# <# 0#) && (y# ># 0#) = if r# /=# 0# then r# +# y# else 0#
679 !r# = x# `remInt#` y#
682 Definitions of the boxed PrimOps; these will be
683 used in the case of partial applications, etc.
686 {-# INLINE plusInt #-}
687 {-# INLINE minusInt #-}
688 {-# INLINE timesInt #-}
689 {-# INLINE quotInt #-}
690 {-# INLINE remInt #-}
691 {-# INLINE negateInt #-}
693 plusInt, minusInt, timesInt, quotInt, remInt, divInt, modInt :: Int -> Int -> Int
694 (I# x) `plusInt` (I# y) = I# (x +# y)
695 (I# x) `minusInt` (I# y) = I# (x -# y)
696 (I# x) `timesInt` (I# y) = I# (x *# y)
697 (I# x) `quotInt` (I# y) = I# (x `quotInt#` y)
698 (I# x) `remInt` (I# y) = I# (x `remInt#` y)
699 (I# x) `divInt` (I# y) = I# (x `divInt#` y)
700 (I# x) `modInt` (I# y) = I# (x `modInt#` y)
703 "x# +# 0#" forall x#. x# +# 0# = x#
704 "0# +# x#" forall x#. 0# +# x# = x#
705 "x# -# 0#" forall x#. x# -# 0# = x#
706 "x# -# x#" forall x#. x# -# x# = 0#
707 "x# *# 0#" forall x#. x# *# 0# = 0#
708 "0# *# x#" forall x#. 0# *# x# = 0#
709 "x# *# 1#" forall x#. x# *# 1# = x#
710 "1# *# x#" forall x#. 1# *# x# = x#
713 negateInt :: Int -> Int
714 negateInt (I# x) = I# (negateInt# x)
717 "x# ># x#" forall x#. x# ># x# = False
718 "x# >=# x#" forall x#. x# >=# x# = True
719 "x# ==# x#" forall x#. x# ==# x# = True
720 "x# /=# x#" forall x#. x# /=# x# = False
721 "x# <# x#" forall x#. x# <# x# = False
722 "x# <=# x#" forall x#. x# <=# x# = True
726 "plusFloat x 0.0" forall x#. plusFloat# x# 0.0# = x#
727 "plusFloat 0.0 x" forall x#. plusFloat# 0.0# x# = x#
728 "minusFloat x 0.0" forall x#. minusFloat# x# 0.0# = x#
729 "minusFloat x x" forall x#. minusFloat# x# x# = 0.0#
730 "timesFloat x 0.0" forall x#. timesFloat# x# 0.0# = 0.0#
731 "timesFloat0.0 x" forall x#. timesFloat# 0.0# x# = 0.0#
732 "timesFloat x 1.0" forall x#. timesFloat# x# 1.0# = x#
733 "timesFloat 1.0 x" forall x#. timesFloat# 1.0# x# = x#
734 "divideFloat x 1.0" forall x#. divideFloat# x# 1.0# = x#
738 "plusDouble x 0.0" forall x#. (+##) x# 0.0## = x#
739 "plusDouble 0.0 x" forall x#. (+##) 0.0## x# = x#
740 "minusDouble x 0.0" forall x#. (-##) x# 0.0## = x#
741 "timesDouble x 1.0" forall x#. (*##) x# 1.0## = x#
742 "timesDouble 1.0 x" forall x#. (*##) 1.0## x# = x#
743 "divideDouble x 1.0" forall x#. (/##) x# 1.0## = x#
747 We'd like to have more rules, but for example:
749 This gives wrong answer (0) for NaN - NaN (should be NaN):
750 "minusDouble x x" forall x#. (-##) x# x# = 0.0##
752 This gives wrong answer (0) for 0 * NaN (should be NaN):
753 "timesDouble 0.0 x" forall x#. (*##) 0.0## x# = 0.0##
755 This gives wrong answer (0) for NaN * 0 (should be NaN):
756 "timesDouble x 0.0" forall x#. (*##) x# 0.0## = 0.0##
758 These are tested by num014.
761 -- Wrappers for the shift operations. The uncheckedShift# family are
762 -- undefined when the amount being shifted by is greater than the size
763 -- in bits of Int#, so these wrappers perform a check and return
764 -- either zero or -1 appropriately.
766 -- Note that these wrappers still produce undefined results when the
767 -- second argument (the shift amount) is negative.
769 -- | Shift the argument left by the specified number of bits
770 -- (which must be non-negative).
771 shiftL# :: Word# -> Int# -> Word#
772 a `shiftL#` b | b >=# WORD_SIZE_IN_BITS# = int2Word# 0#
773 | otherwise = a `uncheckedShiftL#` b
775 -- | Shift the argument right by the specified number of bits
776 -- (which must be non-negative).
777 shiftRL# :: Word# -> Int# -> Word#
778 a `shiftRL#` b | b >=# WORD_SIZE_IN_BITS# = int2Word# 0#
779 | otherwise = a `uncheckedShiftRL#` b
781 -- | Shift the argument left by the specified number of bits
782 -- (which must be non-negative).
783 iShiftL# :: Int# -> Int# -> Int#
784 a `iShiftL#` b | b >=# WORD_SIZE_IN_BITS# = 0#
785 | otherwise = a `uncheckedIShiftL#` b
787 -- | Shift the argument right (signed) by the specified number of bits
788 -- (which must be non-negative).
789 iShiftRA# :: Int# -> Int# -> Int#
790 a `iShiftRA#` b | b >=# WORD_SIZE_IN_BITS# = if a <# 0# then (-1#) else 0#
791 | otherwise = a `uncheckedIShiftRA#` b
793 -- | Shift the argument right (unsigned) by the specified number of bits
794 -- (which must be non-negative).
795 iShiftRL# :: Int# -> Int# -> Int#
796 a `iShiftRL#` b | b >=# WORD_SIZE_IN_BITS# = 0#
797 | otherwise = a `uncheckedIShiftRL#` b
799 #if WORD_SIZE_IN_BITS == 32
801 "narrow32Int#" forall x#. narrow32Int# x# = x#
802 "narrow32Word#" forall x#. narrow32Word# x# = x#
807 "int2Word2Int" forall x#. int2Word# (word2Int# x#) = x#
808 "word2Int2Word" forall x#. word2Int# (int2Word# x#) = x#
812 -- Rules for C strings (the functions themselves are now in GHC.CString)
814 "unpack" [~1] forall a . unpackCString# a = build (unpackFoldrCString# a)
815 "unpack-list" [1] forall a . unpackFoldrCString# a (:) [] = unpackCString# a
816 "unpack-append" forall a n . unpackFoldrCString# a (:) n = unpackAppendCString# a n
818 -- There's a built-in rule (in PrelRules.lhs) for
819 -- unpackFoldr "foo" c (unpackFoldr "baz" c n) = unpackFoldr "foobaz" c n
827 -- | A special argument for the 'Control.Monad.ST.ST' type constructor,
828 -- indexing a state embedded in the 'Prelude.IO' monad by
829 -- 'Control.Monad.ST.stToIO'.