diff --git a/libraries/base/GHC/Base.hs b/libraries/base/GHC/Base.hs
index 82b99a8..052f13f 100644
--- a/libraries/base/GHC/Base.hs
+++ b/libraries/base/GHC/Base.hs
@@ -1,1456 +1,1457 @@
{-
NOTA BENE: Do NOT use ($) anywhere in this module! The type of ($) is
slightly magical (it can return unlifted types), and it is wired in.
But, it is also *defined* in this module, with a non-magical type.
GHC gets terribly confused (and *hangs*) if you try to use ($) in this
module, because it has different types in different scenarios.
This is not a problem in general, because the type ($), being wired in, is not
written out to the interface file, so importing files don't get confused.
The problem is only if ($) is used here. So don't!
---------------------------------------------
The overall structure of the GHC Prelude is a bit tricky.
a) We want to avoid "orphan modules", i.e. ones with instance
decls that don't belong either to a tycon or a class
defined in the same module
b) We want to avoid giant modules
So the rough structure is as follows, in (linearised) dependency order
GHC.Prim Has no implementation. It defines built-in things, and
by importing it you bring them into scope.
The source file is GHC.Prim.hi-boot, which is just
copied to make GHC.Prim.hi
GHC.Base Classes: Eq, Ord, Functor, Monad
Types: list, (), Int, Bool, Ordering, Char, String
Data.Tuple Types: tuples, plus instances for GHC.Base classes
GHC.Show Class: Show, plus instances for GHC.Base/GHC.Tup types
GHC.Enum Class: Enum, plus instances for GHC.Base/GHC.Tup types
Data.Maybe Type: Maybe, plus instances for GHC.Base classes
GHC.List List functions
GHC.Num Class: Num, plus instances for Int
Type: Integer, plus instances for all classes so far (Eq, Ord, Num, Show)
Integer is needed here because it is mentioned in the signature
of 'fromInteger' in class Num
GHC.Real Classes: Real, Integral, Fractional, RealFrac
plus instances for Int, Integer
Types: Ratio, Rational
plus instances for classes so far
Rational is needed here because it is mentioned in the signature
of 'toRational' in class Real
GHC.ST The ST monad, instances and a few helper functions
Ix Classes: Ix, plus instances for Int, Bool, Char, Integer, Ordering, tuples
GHC.Arr Types: Array, MutableArray, MutableVar
Arrays are used by a function in GHC.Float
GHC.Float Classes: Floating, RealFloat
Types: Float, Double, plus instances of all classes so far
This module contains everything to do with floating point.
It is a big module (900 lines)
With a bit of luck, many modules can be compiled without ever reading GHC.Float.hi
Other Prelude modules are much easier with fewer complex dependencies.
-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE CPP
, NoImplicitPrelude
, BangPatterns
, ExplicitForAll
, MagicHash
, UnboxedTuples
, ExistentialQuantification
, RankNTypes
#-}
-- -Wno-orphans is needed for things like:
-- Orphan rule: "x# -# x#" ALWAYS forall x# :: Int# -# x# x# = 0
{-# OPTIONS_GHC -Wno-orphans #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
-- |
-- Module : GHC.Base
-- 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)
--
-- Basic data types and classes.
--
-----------------------------------------------------------------------------
#include "MachDeps.h"
module GHC.Base
(
module GHC.Base,
module GHC.Classes,
module GHC.CString,
module GHC.Magic,
module GHC.Types,
module GHC.Prim, -- Re-export GHC.Prim and [boot] GHC.Err,
-- to avoid lots of people having to
module GHC.Err -- import it explicitly
)
where
import GHC.Types
import GHC.Classes
import GHC.CString
import GHC.Magic
import GHC.Prim
import GHC.Err
import {-# SOURCE #-} GHC.IO (failIO,mplusIO)
import GHC.Tuple () -- Note [Depend on GHC.Tuple]
import GHC.Integer () -- Note [Depend on GHC.Integer]
-- for 'class Semigroup'
import {-# SOURCE #-} GHC.Real (Integral)
import {-# SOURCE #-} Data.Semigroup.Internal ( stimesDefault
, stimesMaybe
, stimesList
, stimesIdempotentMonoid
)
infixr 9 .
infixr 5 ++
infixl 4 <$
infixl 1 >>, >>=
infixr 1 =<<
infixr 0 $, $!
infixl 4 <*>, <*, *>, <**>
default () -- Double isn't available yet
{-
Note [Depend on GHC.Integer]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Integer type is special because TidyPgm uses
GHC.Integer.Type.mkInteger to construct Integer literal values
Currently it reads the interface file whether or not the current
module *has* any Integer literals, so it's important that
GHC.Integer.Type (in package integer-gmp or integer-simple) is
compiled before any other module. (There's a hack in GHC to disable
this for packages ghc-prim, integer-gmp, integer-simple, which aren't
allowed to contain any Integer literals.)
Likewise we implicitly need Integer when deriving things like Eq
instances.
The danger is that if the build system doesn't know about the dependency
on Integer, it'll compile some base module before GHC.Integer.Type,
resulting in:
Failed to load interface for ‘GHC.Integer.Type’
There are files missing in the ‘integer-gmp’ package,
Bottom line: we make GHC.Base depend on GHC.Integer; and everything
else either depends on GHC.Base, or does not have NoImplicitPrelude
(and hence depends on Prelude).
Note [Depend on GHC.Tuple]
~~~~~~~~~~~~~~~~~~~~~~~~~~
Similarly, tuple syntax (or ()) creates an implicit dependency on
GHC.Tuple, so we use the same rule as for Integer --- see Note [Depend on
GHC.Integer] --- to explain this to the build system. We make GHC.Base
depend on GHC.Tuple, and everything else depends on GHC.Base or Prelude.
-}
#if 0
-- for use when compiling GHC.Base itself doesn't work
data Bool = False | True
data Ordering = LT | EQ | GT
data Char = C# Char#
type String = [Char]
data Int = I# Int#
data () = ()
data [] a = MkNil
not True = False
(&&) True True = True
otherwise = True
build = errorWithoutStackTrace "urk"
foldr = errorWithoutStackTrace "urk"
#endif
-- | The 'Maybe' type encapsulates an optional value. A value of type
-- @'Maybe' a@ either contains a value of type @a@ (represented as @'Just' a@),
-- or it is empty (represented as 'Nothing'). Using 'Maybe' is a good way to
-- deal with errors or exceptional cases without resorting to drastic
-- measures such as 'error'.
--
-- The 'Maybe' type is also a monad. It is a simple kind of error
-- monad, where all errors are represented by 'Nothing'. A richer
-- error monad can be built using the 'Data.Either.Either' type.
--
data Maybe a = Nothing | Just a
deriving (Eq, Ord)
infixr 6 <>
-- | The class of semigroups (types with an associative binary operation).
--
-- Instances should satisfy the associativity law:
--
-- * @x '<>' (y '<>' z) = (x '<>' y) '<>' z@
--
-- @since 4.9.0.0
class Semigroup a where
-- | An associative operation.
(<>) :: a -> a -> a
-- | Reduce a non-empty list with @\<\>@
--
-- The default definition should be sufficient, but this can be
-- overridden for efficiency.
--
sconcat :: NonEmpty a -> a
sconcat (a :| as) = go a as where
go b (c:cs) = b <> go c cs
go b [] = b
-- | Repeat a value @n@ times.
--
-- Given that this works on a 'Semigroup' it is allowed to fail if
-- you request 0 or fewer repetitions, and the default definition
-- will do so.
--
-- By making this a member of the class, idempotent semigroups
-- and monoids can upgrade this to execute in /O(1)/ by
-- picking @stimes = 'stimesIdempotent'@ or @stimes =
-- 'stimesIdempotentMonoid'@ respectively.
stimes :: Integral b => b -> a -> a
stimes = stimesDefault
-- | The class of monoids (types with an associative binary operation that
-- has an identity). Instances should satisfy the following laws:
--
-- * @x '<>' 'mempty' = x@
--
-- * @'mempty' '<>' x = x@
--
-- * @x '<>' (y '<>' z) = (x '<>' y) '<>' z@ ('Semigroup' law)
--
-- * @'mconcat' = 'foldr' '(<>)' 'mempty'@
--
-- The method names refer to the monoid of lists under concatenation,
-- but there are many other instances.
--
-- Some types can be viewed as a monoid in more than one way,
-- e.g. both addition and multiplication on numbers.
-- In such cases we often define @newtype@s and make those instances
-- of 'Monoid', e.g. 'Sum' and 'Product'.
--
-- __NOTE__: 'Semigroup' is a superclass of 'Monoid' since /base-4.11.0.0/.
class Semigroup a => Monoid a where
-- | Identity of 'mappend'
mempty :: a
-- | An associative operation
--
-- __NOTE__: This method is redundant and has the default
-- implementation @'mappend' = '(<>)'@ since /base-4.11.0.0/.
mappend :: a -> a -> a
mappend = (<>)
{-# INLINE mappend #-}
-- | Fold a list using the monoid.
--
-- For most types, the default definition for 'mconcat' will be
-- used, but the function is included in the class definition so
-- that an optimized version can be provided for specific types.
mconcat :: [a] -> a
mconcat = foldr mappend mempty
-- | @since 4.9.0.0
instance Semigroup [a] where
(<>) = (++)
{-# INLINE (<>) #-}
stimes = stimesList
-- | @since 2.01
instance Monoid [a] where
{-# INLINE mempty #-}
mempty = []
{-# INLINE mconcat #-}
mconcat xss = [x | xs <- xss, x <- xs]
-- See Note: [List comprehensions and inlining]
{-
Note: [List comprehensions and inlining]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The list monad operations are traditionally described in terms of concatMap:
xs >>= f = concatMap f xs
Similarly, mconcat for lists is just concat. Here in Base, however, we don't
have concatMap, and we'll refrain from adding it here so it won't have to be
hidden in imports. Instead, we use GHC's list comprehension desugaring
mechanism to define mconcat and the Applicative and Monad instances for lists.
We mark them INLINE because the inliner is not generally too keen to inline
build forms such as the ones these desugar to without our insistence. Defining
these using list comprehensions instead of foldr has an additional potential
benefit, as described in compiler/deSugar/DsListComp.hs: if optimizations
needed to make foldr/build forms efficient are turned off, we'll get reasonably
efficient translations anyway.
-}
-- | @since 4.9.0.0
instance Semigroup (NonEmpty a) where
(a :| as) <> ~(b :| bs) = a :| (as ++ b : bs)
-- | @since 4.9.0.0
instance Semigroup b => Semigroup (a -> b) where
f <> g = \x -> f x <> g x
stimes n f e = stimes n (f e)
-- | @since 2.01
instance Monoid b => Monoid (a -> b) where
mempty _ = mempty
-- | @since 4.9.0.0
instance Semigroup () where
_ <> _ = ()
sconcat _ = ()
stimes _ _ = ()
-- | @since 2.01
instance Monoid () where
-- Should it be strict?
mempty = ()
mconcat _ = ()
-- | @since 4.9.0.0
instance (Semigroup a, Semigroup b) => Semigroup (a, b) where
(a,b) <> (a',b') = (a<>a',b<>b')
stimes n (a,b) = (stimes n a, stimes n b)
-- | @since 2.01
instance (Monoid a, Monoid b) => Monoid (a,b) where
mempty = (mempty, mempty)
-- | @since 4.9.0.0
instance (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) where
(a,b,c) <> (a',b',c') = (a<>a',b<>b',c<>c')
stimes n (a,b,c) = (stimes n a, stimes n b, stimes n c)
-- | @since 2.01
instance (Monoid a, Monoid b, Monoid c) => Monoid (a,b,c) where
mempty = (mempty, mempty, mempty)
-- | @since 4.9.0.0
instance (Semigroup a, Semigroup b, Semigroup c, Semigroup d)
=> Semigroup (a, b, c, d) where
(a,b,c,d) <> (a',b',c',d') = (a<>a',b<>b',c<>c',d<>d')
stimes n (a,b,c,d) = (stimes n a, stimes n b, stimes n c, stimes n d)
-- | @since 2.01
instance (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a,b,c,d) where
mempty = (mempty, mempty, mempty, mempty)
-- | @since 4.9.0.0
instance (Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e)
=> Semigroup (a, b, c, d, e) where
(a,b,c,d,e) <> (a',b',c',d',e') = (a<>a',b<>b',c<>c',d<>d',e<>e')
stimes n (a,b,c,d,e) =
(stimes n a, stimes n b, stimes n c, stimes n d, stimes n e)
-- | @since 2.01
instance (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) =>
Monoid (a,b,c,d,e) where
mempty = (mempty, mempty, mempty, mempty, mempty)
-- | @since 4.9.0.0
instance Semigroup Ordering where
LT <> _ = LT
EQ <> y = y
GT <> _ = GT
stimes = stimesIdempotentMonoid
-- lexicographical ordering
-- | @since 2.01
instance Monoid Ordering where
mempty = EQ
-- | @since 4.9.0.0
instance Semigroup a => Semigroup (Maybe a) where
Nothing <> b = b
a <> Nothing = a
Just a <> Just b = Just (a <> b)
stimes = stimesMaybe
-- | Lift a semigroup into 'Maybe' forming a 'Monoid' according to
-- : \"Any semigroup @S@ may be
-- turned into a monoid simply by adjoining an element @e@ not in @S@
--- and defining @e*e = e@ and @e*s = s = s*e@ for all @s ∈ S@.\" Since
--- there used to be no \"Semigroup\" typeclass providing just 'mappend',
--- we use 'Monoid' instead.
+-- and defining @e*e = e@ and @e*s = s = s*e@ for all @s ∈ S@.\"
+--
+-- /Since 4.11.0/: constraint on inner @a@ value generalised from
+-- 'Monoid' to 'Semigroup'.
--
-- @since 2.01
-instance Monoid a => Monoid (Maybe a) where
+instance Semigroup a => Monoid (Maybe a) where
mempty = Nothing
-- | For tuples, the 'Monoid' constraint on @a@ determines
-- how the first values merge.
-- For example, 'String's concatenate:
--
-- > ("hello ", (+15)) <*> ("world!", 2002)
-- > ("hello world!",2017)
--
-- @since 2.01
instance Monoid a => Applicative ((,) a) where
pure x = (mempty, x)
(u, f) <*> (v, x) = (u <> v, f x)
liftA2 f (u, x) (v, y) = (u <> v, f x y)
-- | @since 4.9.0.0
instance Monoid a => Monad ((,) a) where
(u, a) >>= k = case k a of (v, b) -> (u <> v, b)
-- | @since 4.10.0.0
instance Semigroup a => Semigroup (IO a) where
(<>) = liftA2 (<>)
-- | @since 4.9.0.0
instance Monoid a => Monoid (IO a) where
mempty = pure mempty
{- | The 'Functor' class is used for types that can be mapped over.
Instances of 'Functor' should satisfy the following laws:
> fmap id == id
> fmap (f . g) == fmap f . fmap g
The instances of 'Functor' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'
satisfy these laws.
-}
class Functor f where
fmap :: (a -> b) -> f a -> f b
-- | Replace all locations in the input with the same value.
-- The default definition is @'fmap' . 'const'@, but this may be
-- overridden with a more efficient version.
(<$) :: a -> f b -> f a
(<$) = fmap . const
-- | A functor with application, providing operations to
--
-- * embed pure expressions ('pure'), and
--
-- * sequence computations and combine their results ('<*>' and 'liftA2').
--
-- A minimal complete definition must include implementations of 'pure'
-- and of either '<*>' or 'liftA2'. If it defines both, then they must behave
-- the same as their default definitions:
--
-- @('<*>') = 'liftA2' 'id'@
--
-- @'liftA2' f x y = f '<$>' x '<*>' y@
--
-- Further, any definition must satisfy the following:
--
-- [/identity/]
--
-- @'pure' 'id' '<*>' v = v@
--
-- [/composition/]
--
-- @'pure' (.) '<*>' u '<*>' v '<*>' w = u '<*>' (v '<*>' w)@
--
-- [/homomorphism/]
--
-- @'pure' f '<*>' 'pure' x = 'pure' (f x)@
--
-- [/interchange/]
--
-- @u '<*>' 'pure' y = 'pure' ('$' y) '<*>' u@
--
--
-- The other methods have the following default definitions, which may
-- be overridden with equivalent specialized implementations:
--
-- * @u '*>' v = ('id' '<$' u) '<*>' v@
--
-- * @u '<*' v = 'liftA2' 'const' u v@
--
-- As a consequence of these laws, the 'Functor' instance for @f@ will satisfy
--
-- * @'fmap' f x = 'pure' f '<*>' x@
--
--
-- It may be useful to note that supposing
--
-- @forall x y. p (q x y) = f x . g y@
--
-- it follows from the above that
--
-- @'liftA2' p ('liftA2' q u v) = 'liftA2' f u . 'liftA2' g v@
--
--
-- If @f@ is also a 'Monad', it should satisfy
--
-- * @'pure' = 'return'@
--
-- * @('<*>') = 'ap'@
--
-- * @('*>') = ('>>')@
--
-- (which implies that 'pure' and '<*>' satisfy the applicative functor laws).
class Functor f => Applicative f where
{-# MINIMAL pure, ((<*>) | liftA2) #-}
-- | Lift a value.
pure :: a -> f a
-- | Sequential application.
--
-- A few functors support an implementation of '<*>' that is more
-- efficient than the default one.
(<*>) :: f (a -> b) -> f a -> f b
(<*>) = liftA2 id
-- | Lift a binary function to actions.
--
-- Some functors support an implementation of 'liftA2' that is more
-- efficient than the default one. In particular, if 'fmap' is an
-- expensive operation, it is likely better to use 'liftA2' than to
-- 'fmap' over the structure and then use '<*>'.
liftA2 :: (a -> b -> c) -> f a -> f b -> f c
liftA2 f x = (<*>) (fmap f x)
-- | Sequence actions, discarding the value of the first argument.
(*>) :: f a -> f b -> f b
a1 *> a2 = (id <$ a1) <*> a2
-- This is essentially the same as liftA2 (flip const), but if the
-- Functor instance has an optimized (<$), it may be better to use
-- that instead. Before liftA2 became a method, this definition
-- was strictly better, but now it depends on the functor. For a
-- functor supporting a sharing-enhancing (<$), this definition
-- may reduce allocation by preventing a1 from ever being fully
-- realized. In an implementation with a boring (<$) but an optimizing
-- liftA2, it would likely be better to define (*>) using liftA2.
-- | Sequence actions, discarding the value of the second argument.
(<*) :: f a -> f b -> f a
(<*) = liftA2 const
-- | A variant of '<*>' with the arguments reversed.
(<**>) :: Applicative f => f a -> f (a -> b) -> f b
(<**>) = liftA2 (\a f -> f a)
-- Don't use $ here, see the note at the top of the page
-- | Lift a function to actions.
-- This function may be used as a value for `fmap` in a `Functor` instance.
liftA :: Applicative f => (a -> b) -> f a -> f b
liftA f a = pure f <*> a
-- Caution: since this may be used for `fmap`, we can't use the obvious
-- definition of liftA = fmap.
-- | Lift a ternary function to actions.
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 f a b c = liftA2 f a b <*> c
{-# INLINABLE liftA #-}
{-# SPECIALISE liftA :: (a1->r) -> IO a1 -> IO r #-}
{-# SPECIALISE liftA :: (a1->r) -> Maybe a1 -> Maybe r #-}
{-# INLINABLE liftA3 #-}
{-# SPECIALISE liftA3 :: (a1->a2->a3->r) -> IO a1 -> IO a2 -> IO a3 -> IO r #-}
{-# SPECIALISE liftA3 :: (a1->a2->a3->r) ->
Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe r #-}
-- | The 'join' function is the conventional monad join operator. It
-- is used to remove one level of monadic structure, projecting its
-- bound argument into the outer level.
join :: (Monad m) => m (m a) -> m a
join x = x >>= id
{- | The 'Monad' class defines the basic operations over a /monad/,
a concept from a branch of mathematics known as /category theory/.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an /abstract datatype/ of actions.
Haskell's @do@ expressions provide a convenient syntax for writing
monadic expressions.
Instances of 'Monad' should satisfy the following laws:
* @'return' a '>>=' k = k a@
* @m '>>=' 'return' = m@
* @m '>>=' (\\x -> k x '>>=' h) = (m '>>=' k) '>>=' h@
Furthermore, the 'Monad' and 'Applicative' operations should relate as follows:
* @'pure' = 'return'@
* @('<*>') = 'ap'@
The above laws imply:
* @'fmap' f xs = xs '>>=' 'return' . f@
* @('>>') = ('*>')@
and that 'pure' and ('<*>') satisfy the applicative functor laws.
The instances of 'Monad' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'
defined in the "Prelude" satisfy these laws.
-}
class Applicative m => Monad m where
-- | Sequentially compose two actions, passing any value produced
-- by the first as an argument to the second.
(>>=) :: forall a b. m a -> (a -> m b) -> m b
-- | Sequentially compose two actions, discarding any value produced
-- by the first, like sequencing operators (such as the semicolon)
-- in imperative languages.
(>>) :: forall a b. m a -> m b -> m b
m >> k = m >>= \_ -> k -- See Note [Recursive bindings for Applicative/Monad]
{-# INLINE (>>) #-}
-- | Inject a value into the monadic type.
return :: a -> m a
return = pure
-- | Fail with a message. This operation is not part of the
-- mathematical definition of a monad, but is invoked on pattern-match
-- failure in a @do@ expression.
--
-- As part of the MonadFail proposal (MFP), this function is moved
-- to its own class 'MonadFail' (see "Control.Monad.Fail" for more
-- details). The definition here will be removed in a future
-- release.
fail :: String -> m a
fail s = errorWithoutStackTrace s
{- Note [Recursive bindings for Applicative/Monad]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The original Applicative/Monad proposal stated that after
implementation, the designated implementation of (>>) would become
(>>) :: forall a b. m a -> m b -> m b
(>>) = (*>)
by default. You might be inclined to change this to reflect the stated
proposal, but you really shouldn't! Why? Because people tend to define
such instances the /other/ way around: in particular, it is perfectly
legitimate to define an instance of Applicative (*>) in terms of (>>),
which would lead to an infinite loop for the default implementation of
Monad! And people do this in the wild.
This turned into a nasty bug that was tricky to track down, and rather
than eliminate it everywhere upstream, it's easier to just retain the
original default.
-}
-- | Same as '>>=', but with the arguments interchanged.
{-# SPECIALISE (=<<) :: (a -> [b]) -> [a] -> [b] #-}
(=<<) :: Monad m => (a -> m b) -> m a -> m b
f =<< x = x >>= f
-- | Conditional execution of 'Applicative' expressions. For example,
--
-- > when debug (putStrLn "Debugging")
--
-- will output the string @Debugging@ if the Boolean value @debug@
-- is 'True', and otherwise do nothing.
when :: (Applicative f) => Bool -> f () -> f ()
{-# INLINABLE when #-}
{-# SPECIALISE when :: Bool -> IO () -> IO () #-}
{-# SPECIALISE when :: Bool -> Maybe () -> Maybe () #-}
when p s = if p then s else pure ()
-- | Evaluate each action in the sequence from left to right,
-- and collect the results.
sequence :: Monad m => [m a] -> m [a]
{-# INLINE sequence #-}
sequence = mapM id
-- Note: [sequence and mapM]
-- | @'mapM' f@ is equivalent to @'sequence' . 'map' f@.
mapM :: Monad m => (a -> m b) -> [a] -> m [b]
{-# INLINE mapM #-}
mapM f as = foldr k (return []) as
where
k a r = do { x <- f a; xs <- r; return (x:xs) }
{-
Note: [sequence and mapM]
~~~~~~~~~~~~~~~~~~~~~~~~~
Originally, we defined
mapM f = sequence . map f
This relied on list fusion to produce efficient code for mapM, and led to
excessive allocation in cryptarithm2. Defining
sequence = mapM id
relies only on inlining a tiny function (id) and beta reduction, which tends to
be a more reliable aspect of simplification. Indeed, this does not lead to
similar problems in nofib.
-}
-- | Promote a function to a monad.
liftM :: (Monad m) => (a1 -> r) -> m a1 -> m r
liftM f m1 = do { x1 <- m1; return (f x1) }
-- | Promote a function to a monad, scanning the monadic arguments from
-- left to right. For example,
--
-- > liftM2 (+) [0,1] [0,2] = [0,2,1,3]
-- > liftM2 (+) (Just 1) Nothing = Nothing
--
liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 f m1 m2 = do { x1 <- m1; x2 <- m2; return (f x1 x2) }
-- Caution: since this may be used for `liftA2`, we can't use the obvious
-- definition of liftM2 = liftA2.
-- | Promote a function to a monad, scanning the monadic arguments from
-- left to right (cf. 'liftM2').
liftM3 :: (Monad m) => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
liftM3 f m1 m2 m3 = do { x1 <- m1; x2 <- m2; x3 <- m3; return (f x1 x2 x3) }
-- | Promote a function to a monad, scanning the monadic arguments from
-- left to right (cf. 'liftM2').
liftM4 :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
liftM4 f m1 m2 m3 m4 = do { x1 <- m1; x2 <- m2; x3 <- m3; x4 <- m4; return (f x1 x2 x3 x4) }
-- | Promote a function to a monad, scanning the monadic arguments from
-- left to right (cf. 'liftM2').
liftM5 :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
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) }
{-# INLINABLE liftM #-}
{-# SPECIALISE liftM :: (a1->r) -> IO a1 -> IO r #-}
{-# SPECIALISE liftM :: (a1->r) -> Maybe a1 -> Maybe r #-}
{-# INLINABLE liftM2 #-}
{-# SPECIALISE liftM2 :: (a1->a2->r) -> IO a1 -> IO a2 -> IO r #-}
{-# SPECIALISE liftM2 :: (a1->a2->r) -> Maybe a1 -> Maybe a2 -> Maybe r #-}
{-# INLINABLE liftM3 #-}
{-# SPECIALISE liftM3 :: (a1->a2->a3->r) -> IO a1 -> IO a2 -> IO a3 -> IO r #-}
{-# SPECIALISE liftM3 :: (a1->a2->a3->r) -> Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe r #-}
{-# INLINABLE liftM4 #-}
{-# SPECIALISE liftM4 :: (a1->a2->a3->a4->r) -> IO a1 -> IO a2 -> IO a3 -> IO a4 -> IO r #-}
{-# SPECIALISE liftM4 :: (a1->a2->a3->a4->r) -> Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe a4 -> Maybe r #-}
{-# INLINABLE liftM5 #-}
{-# SPECIALISE liftM5 :: (a1->a2->a3->a4->a5->r) -> IO a1 -> IO a2 -> IO a3 -> IO a4 -> IO a5 -> IO r #-}
{-# SPECIALISE liftM5 :: (a1->a2->a3->a4->a5->r) -> Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe a4 -> Maybe a5 -> Maybe r #-}
{- | In many situations, the 'liftM' operations can be replaced by uses of
'ap', which promotes function application.
> return f `ap` x1 `ap` ... `ap` xn
is equivalent to
> liftMn f x1 x2 ... xn
-}
ap :: (Monad m) => m (a -> b) -> m a -> m b
ap m1 m2 = do { x1 <- m1; x2 <- m2; return (x1 x2) }
-- Since many Applicative instances define (<*>) = ap, we
-- cannot define ap = (<*>)
{-# INLINABLE ap #-}
{-# SPECIALISE ap :: IO (a -> b) -> IO a -> IO b #-}
{-# SPECIALISE ap :: Maybe (a -> b) -> Maybe a -> Maybe b #-}
-- instances for Prelude types
-- | @since 2.01
instance Functor ((->) r) where
fmap = (.)
-- | @since 2.01
instance Applicative ((->) a) where
pure = const
(<*>) f g x = f x (g x)
liftA2 q f g x = q (f x) (g x)
-- | @since 2.01
instance Monad ((->) r) where
f >>= k = \ r -> k (f r) r
-- | @since 2.01
instance Functor ((,) a) where
fmap f (x,y) = (x, f y)
-- | @since 2.01
instance Functor Maybe where
fmap _ Nothing = Nothing
fmap f (Just a) = Just (f a)
-- | @since 2.01
instance Applicative Maybe where
pure = Just
Just f <*> m = fmap f m
Nothing <*> _m = Nothing
liftA2 f (Just x) (Just y) = Just (f x y)
liftA2 _ _ _ = Nothing
Just _m1 *> m2 = m2
Nothing *> _m2 = Nothing
-- | @since 2.01
instance Monad Maybe where
(Just x) >>= k = k x
Nothing >>= _ = Nothing
(>>) = (*>)
fail _ = Nothing
-- -----------------------------------------------------------------------------
-- The Alternative class definition
infixl 3 <|>
-- | A monoid on applicative functors.
--
-- If defined, 'some' and 'many' should be the least solutions
-- of the equations:
--
-- * @'some' v = (:) '<$>' v '<*>' 'many' v@
--
-- * @'many' v = 'some' v '<|>' 'pure' []@
class Applicative f => Alternative f where
-- | The identity of '<|>'
empty :: f a
-- | An associative binary operation
(<|>) :: f a -> f a -> f a
-- | One or more.
some :: f a -> f [a]
some v = some_v
where
many_v = some_v <|> pure []
some_v = liftA2 (:) v many_v
-- | Zero or more.
many :: f a -> f [a]
many v = many_v
where
many_v = some_v <|> pure []
some_v = liftA2 (:) v many_v
-- | @since 2.01
instance Alternative Maybe where
empty = Nothing
Nothing <|> r = r
l <|> _ = l
-- -----------------------------------------------------------------------------
-- The MonadPlus class definition
-- | Monads that also support choice and failure.
class (Alternative m, Monad m) => MonadPlus m where
-- | the identity of 'mplus'. It should also satisfy the equations
--
-- > mzero >>= f = mzero
-- > v >> mzero = mzero
--
mzero :: m a
mzero = empty
-- | an associative operation
mplus :: m a -> m a -> m a
mplus = (<|>)
-- | @since 2.01
instance MonadPlus Maybe
---------------------------------------------
-- The non-empty list type
infixr 5 :|
-- | Non-empty (and non-strict) list type.
--
-- @since 4.9.0.0
data NonEmpty a = a :| [a]
deriving (Eq, Ord)
-- | @since 4.9.0.0
instance Functor NonEmpty where
fmap f ~(a :| as) = f a :| fmap f as
b <$ ~(_ :| as) = b :| (b <$ as)
-- | @since 4.9.0.0
instance Applicative NonEmpty where
pure a = a :| []
(<*>) = ap
liftA2 = liftM2
-- | @since 4.9.0.0
instance Monad NonEmpty where
~(a :| as) >>= f = b :| (bs ++ bs')
where b :| bs = f a
bs' = as >>= toList . f
toList ~(c :| cs) = c : cs
----------------------------------------------
-- The list type
-- | @since 2.01
instance Functor [] where
{-# INLINE fmap #-}
fmap = map
-- See Note: [List comprehensions and inlining]
-- | @since 2.01
instance Applicative [] where
{-# INLINE pure #-}
pure x = [x]
{-# INLINE (<*>) #-}
fs <*> xs = [f x | f <- fs, x <- xs]
{-# INLINE liftA2 #-}
liftA2 f xs ys = [f x y | x <- xs, y <- ys]
{-# INLINE (*>) #-}
xs *> ys = [y | _ <- xs, y <- ys]
-- See Note: [List comprehensions and inlining]
-- | @since 2.01
instance Monad [] where
{-# INLINE (>>=) #-}
xs >>= f = [y | x <- xs, y <- f x]
{-# INLINE (>>) #-}
(>>) = (*>)
{-# INLINE fail #-}
fail _ = []
-- | @since 2.01
instance Alternative [] where
empty = []
(<|>) = (++)
-- | @since 2.01
instance MonadPlus []
{-
A few list functions that appear here because they are used here.
The rest of the prelude list functions are in GHC.List.
-}
----------------------------------------------
-- foldr/build/augment
----------------------------------------------
-- | 'foldr', applied to a binary operator, a starting value (typically
-- the right-identity of the operator), and a list, reduces the list
-- using the binary operator, from right to left:
--
-- > foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
foldr :: (a -> b -> b) -> b -> [a] -> b
-- foldr _ z [] = z
-- foldr f z (x:xs) = f x (foldr f z xs)
{-# INLINE [0] foldr #-}
-- Inline only in the final stage, after the foldr/cons rule has had a chance
-- Also note that we inline it when it has *two* parameters, which are the
-- ones we are keen about specialising!
foldr k z = go
where
go [] = z
go (y:ys) = y `k` go ys
-- | A list producer that can be fused with 'foldr'.
-- This function is merely
--
-- > build g = g (:) []
--
-- but GHC's simplifier will transform an expression of the form
-- @'foldr' k z ('build' g)@, which may arise after inlining, to @g k z@,
-- which avoids producing an intermediate list.
build :: forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
{-# INLINE [1] build #-}
-- The INLINE is important, even though build is tiny,
-- because it prevents [] getting inlined in the version that
-- appears in the interface file. If [] *is* inlined, it
-- won't match with [] appearing in rules in an importing module.
--
-- The "1" says to inline in phase 1
build g = g (:) []
-- | A list producer that can be fused with 'foldr'.
-- This function is merely
--
-- > augment g xs = g (:) xs
--
-- but GHC's simplifier will transform an expression of the form
-- @'foldr' k z ('augment' g xs)@, which may arise after inlining, to
-- @g k ('foldr' k z xs)@, which avoids producing an intermediate list.
augment :: forall a. (forall b. (a->b->b) -> b -> b) -> [a] -> [a]
{-# INLINE [1] augment #-}
augment g xs = g (:) xs
{-# RULES
"fold/build" forall k z (g::forall b. (a->b->b) -> b -> b) .
foldr k z (build g) = g k z
"foldr/augment" forall k z xs (g::forall b. (a->b->b) -> b -> b) .
foldr k z (augment g xs) = g k (foldr k z xs)
"foldr/id" foldr (:) [] = \x -> x
"foldr/app" [1] forall ys. foldr (:) ys = \xs -> xs ++ ys
-- Only activate this from phase 1, because that's
-- when we disable the rule that expands (++) into foldr
-- The foldr/cons rule looks nice, but it can give disastrously
-- bloated code when commpiling
-- array (a,b) [(1,2), (2,2), (3,2), ...very long list... ]
-- i.e. when there are very very long literal lists
-- So I've disabled it for now. We could have special cases
-- for short lists, I suppose.
-- "foldr/cons" forall k z x xs. foldr k z (x:xs) = k x (foldr k z xs)
"foldr/single" forall k z x. foldr k z [x] = k x z
"foldr/nil" forall k z. foldr k z [] = z
"foldr/cons/build" forall k z x (g::forall b. (a->b->b) -> b -> b) .
foldr k z (x:build g) = k x (g k z)
"augment/build" forall (g::forall b. (a->b->b) -> b -> b)
(h::forall b. (a->b->b) -> b -> b) .
augment g (build h) = build (\c n -> g c (h c n))
"augment/nil" forall (g::forall b. (a->b->b) -> b -> b) .
augment g [] = build g
#-}
-- This rule is true, but not (I think) useful:
-- augment g (augment h t) = augment (\cn -> g c (h c n)) t
----------------------------------------------
-- map
----------------------------------------------
-- | 'map' @f xs@ is the list obtained by applying @f@ to each element
-- of @xs@, i.e.,
--
-- > map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
-- > map f [x1, x2, ...] == [f x1, f x2, ...]
map :: (a -> b) -> [a] -> [b]
{-# NOINLINE [0] map #-}
-- We want the RULEs "map" and "map/coerce" to fire first.
-- map is recursive, so won't inline anyway,
-- but saying so is more explicit, and silences warnings
map _ [] = []
map f (x:xs) = f x : map f xs
-- Note eta expanded
mapFB :: (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst
{-# INLINE [0] mapFB #-} -- See Note [Inline FB functions] in GHC.List
mapFB c f = \x ys -> c (f x) ys
{- Note [The rules for map]
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The rules for map work like this.
* Up to (but not including) phase 1, we use the "map" rule to
rewrite all saturated applications of map with its build/fold
form, hoping for fusion to happen.
In phase 1 and 0, we switch off that rule, inline build, and
switch on the "mapList" rule, which rewrites the foldr/mapFB
thing back into plain map.
It's important that these two rules aren't both active at once
(along with build's unfolding) else we'd get an infinite loop
in the rules. Hence the activation control below.
* This same pattern is followed by many other functions:
e.g. append, filter, iterate, repeat, etc. in GHC.List
See also Note [Inline FB functions] in GHC.List
* The "mapFB" rule optimises compositions of map
* The "mapFB/id" rule gets rid of 'map id' calls.
You might think that (mapFB c id) will turn into c simply
when mapFB is inlined; but before that happens the "mapList"
rule turns
(foldr (mapFB (:) id) [] a
back into
map id
Which is not very clever.
* Any similarity to the Functor laws for [] is expected.
-}
{-# RULES
"map" [~1] forall f xs. map f xs = build (\c n -> foldr (mapFB c f) n xs)
"mapList" [1] forall f. foldr (mapFB (:) f) [] = map f
"mapFB" forall c f g. mapFB (mapFB c f) g = mapFB c (f.g)
"mapFB/id" forall c. mapFB c (\x -> x) = c
#-}
-- See Breitner, Eisenberg, Peyton Jones, and Weirich, "Safe Zero-cost
-- Coercions for Haskell", section 6.5:
-- http://research.microsoft.com/en-us/um/people/simonpj/papers/ext-f/coercible.pdf
{-# RULES "map/coerce" [1] map coerce = coerce #-}
----------------------------------------------
-- append
----------------------------------------------
-- | Append two lists, i.e.,
--
-- > [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
-- > [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
--
-- If the first list is not finite, the result is the first list.
(++) :: [a] -> [a] -> [a]
{-# NOINLINE [1] (++) #-} -- We want the RULE to fire first.
-- It's recursive, so won't inline anyway,
-- but saying so is more explicit
(++) [] ys = ys
(++) (x:xs) ys = x : xs ++ ys
{-# RULES
"++" [~1] forall xs ys. xs ++ ys = augment (\c n -> foldr c n xs) ys
#-}
-- |'otherwise' is defined as the value 'True'. It helps to make
-- guards more readable. eg.
--
-- > f x | x < 0 = ...
-- > | otherwise = ...
otherwise :: Bool
otherwise = True
----------------------------------------------
-- Type Char and String
----------------------------------------------
-- | A 'String' is a list of characters. String constants in Haskell are values
-- of type 'String'.
--
type String = [Char]
unsafeChr :: Int -> Char
unsafeChr (I# i#) = C# (chr# i#)
-- | The 'Prelude.fromEnum' method restricted to the type 'Data.Char.Char'.
ord :: Char -> Int
ord (C# c#) = I# (ord# c#)
-- | This 'String' equality predicate is used when desugaring
-- pattern-matches against strings.
eqString :: String -> String -> Bool
eqString [] [] = True
eqString (c1:cs1) (c2:cs2) = c1 == c2 && cs1 `eqString` cs2
eqString _ _ = False
{-# RULES "eqString" (==) = eqString #-}
-- eqString also has a BuiltInRule in PrelRules.hs:
-- eqString (unpackCString# (Lit s1)) (unpackCString# (Lit s2)) = s1==s2
----------------------------------------------
-- 'Int' related definitions
----------------------------------------------
maxInt, minInt :: Int
{- Seems clumsy. Should perhaps put minInt and MaxInt directly into MachDeps.h -}
#if WORD_SIZE_IN_BITS == 31
minInt = I# (-0x40000000#)
maxInt = I# 0x3FFFFFFF#
#elif WORD_SIZE_IN_BITS == 32
minInt = I# (-0x80000000#)
maxInt = I# 0x7FFFFFFF#
#else
minInt = I# (-0x8000000000000000#)
maxInt = I# 0x7FFFFFFFFFFFFFFF#
#endif
----------------------------------------------
-- The function type
----------------------------------------------
-- | Identity function.
--
-- > id x = x
id :: a -> a
id x = x
-- Assertion function. This simply ignores its boolean argument.
-- The compiler may rewrite it to @('assertError' line)@.
-- | If the first argument evaluates to 'True', then the result is the
-- second argument. Otherwise an 'AssertionFailed' exception is raised,
-- containing a 'String' with the source file and line number of the
-- call to 'assert'.
--
-- Assertions can normally be turned on or off with a compiler flag
-- (for GHC, assertions are normally on unless optimisation is turned on
-- with @-O@ or the @-fignore-asserts@
-- option is given). When assertions are turned off, the first
-- argument to 'assert' is ignored, and the second argument is
-- returned as the result.
-- SLPJ: in 5.04 etc 'assert' is in GHC.Prim,
-- but from Template Haskell onwards it's simply
-- defined here in Base.hs
assert :: Bool -> a -> a
assert _pred r = r
breakpoint :: a -> a
breakpoint r = r
breakpointCond :: Bool -> a -> a
breakpointCond _ r = r
data Opaque = forall a. O a
-- | @const x@ is a unary function which evaluates to @x@ for all inputs.
--
-- >>> const 42 "hello"
-- 42
--
-- >>> map (const 42) [0..3]
-- [42,42,42,42]
const :: a -> b -> a
const x _ = x
-- | Function composition.
{-# INLINE (.) #-}
-- Make sure it has TWO args only on the left, so that it inlines
-- when applied to two functions, even if there is no final argument
(.) :: (b -> c) -> (a -> b) -> a -> c
(.) f g = \x -> f (g x)
-- | @'flip' f@ takes its (first) two arguments in the reverse order of @f@.
--
-- >>> flip (++) "hello" "world"
-- "worldhello"
flip :: (a -> b -> c) -> b -> a -> c
flip f x y = f y x
-- | Application operator. This operator is redundant, since ordinary
-- application @(f x)@ means the same as @(f '$' x)@. However, '$' has
-- low, right-associative binding precedence, so it sometimes allows
-- parentheses to be omitted; for example:
--
-- > f $ g $ h x = f (g (h x))
--
-- It is also useful in higher-order situations, such as @'map' ('$' 0) xs@,
-- or @'Data.List.zipWith' ('$') fs xs@.
{-# INLINE ($) #-}
($) :: (a -> b) -> a -> b
f $ x = f x
-- | Strict (call-by-value) application operator. It takes a function and an
-- argument, evaluates the argument to weak head normal form (WHNF), then calls
-- the function with that value.
($!) :: (a -> b) -> a -> b
f $! x = let !vx = x in f vx -- see #2273
-- | @'until' p f@ yields the result of applying @f@ until @p@ holds.
until :: (a -> Bool) -> (a -> a) -> a -> a
until p f = go
where
go x | p x = x
| otherwise = go (f x)
-- | 'asTypeOf' is a type-restricted version of 'const'. It is usually
-- used as an infix operator, and its typing forces its first argument
-- (which is usually overloaded) to have the same type as the second.
asTypeOf :: a -> a -> a
asTypeOf = const
----------------------------------------------
-- Functor/Applicative/Monad instances for IO
----------------------------------------------
-- | @since 2.01
instance Functor IO where
fmap f x = x >>= (pure . f)
-- | @since 2.01
instance Applicative IO where
{-# INLINE pure #-}
{-# INLINE (*>) #-}
{-# INLINE liftA2 #-}
pure = returnIO
(*>) = thenIO
(<*>) = ap
liftA2 = liftM2
-- | @since 2.01
instance Monad IO where
{-# INLINE (>>) #-}
{-# INLINE (>>=) #-}
(>>) = (*>)
(>>=) = bindIO
fail s = failIO s
-- | @since 4.9.0.0
instance Alternative IO where
empty = failIO "mzero"
(<|>) = mplusIO
-- | @since 4.9.0.0
instance MonadPlus IO
returnIO :: a -> IO a
returnIO x = IO (\ s -> (# s, x #))
bindIO :: IO a -> (a -> IO b) -> IO b
bindIO (IO m) k = IO (\ s -> case m s of (# new_s, a #) -> unIO (k a) new_s)
thenIO :: IO a -> IO b -> IO b
thenIO (IO m) k = IO (\ s -> case m s of (# new_s, _ #) -> unIO k new_s)
unIO :: IO a -> (State# RealWorld -> (# State# RealWorld, a #))
unIO (IO a) = a
{- |
Returns the 'tag' of a constructor application; this function is used
by the deriving code for Eq, Ord and Enum.
The primitive dataToTag# requires an evaluated constructor application
as its argument, so we provide getTag as a wrapper that performs the
evaluation before calling dataToTag#. We could have dataToTag#
evaluate its argument, but we prefer to do it this way because (a)
dataToTag# can be an inline primop if it doesn't need to do any
evaluation, and (b) we want to expose the evaluation to the
simplifier, because it might be possible to eliminate the evaluation
in the case when the argument is already known to be evaluated.
-}
{-# INLINE getTag #-}
getTag :: a -> Int#
getTag !x = dataToTag# x
----------------------------------------------
-- Numeric primops
----------------------------------------------
-- Definitions of the boxed PrimOps; these will be
-- used in the case of partial applications, etc.
{-# INLINE quotInt #-}
{-# INLINE remInt #-}
quotInt, remInt, divInt, modInt :: Int -> Int -> Int
(I# x) `quotInt` (I# y) = I# (x `quotInt#` y)
(I# x) `remInt` (I# y) = I# (x `remInt#` y)
(I# x) `divInt` (I# y) = I# (x `divInt#` y)
(I# x) `modInt` (I# y) = I# (x `modInt#` y)
quotRemInt :: Int -> Int -> (Int, Int)
(I# x) `quotRemInt` (I# y) = case x `quotRemInt#` y of
(# q, r #) ->
(I# q, I# r)
divModInt :: Int -> Int -> (Int, Int)
(I# x) `divModInt` (I# y) = case x `divModInt#` y of
(# q, r #) -> (I# q, I# r)
divModInt# :: Int# -> Int# -> (# Int#, Int# #)
x# `divModInt#` y#
| isTrue# (x# ># 0#) && isTrue# (y# <# 0#) =
case (x# -# 1#) `quotRemInt#` y# of
(# q, r #) -> (# q -# 1#, r +# y# +# 1# #)
| isTrue# (x# <# 0#) && isTrue# (y# ># 0#) =
case (x# +# 1#) `quotRemInt#` y# of
(# q, r #) -> (# q -# 1#, r +# y# -# 1# #)
| otherwise =
x# `quotRemInt#` y#
-- Wrappers for the shift operations. The uncheckedShift# family are
-- undefined when the amount being shifted by is greater than the size
-- in bits of Int#, so these wrappers perform a check and return
-- either zero or -1 appropriately.
--
-- Note that these wrappers still produce undefined results when the
-- second argument (the shift amount) is negative.
-- | Shift the argument left by the specified number of bits
-- (which must be non-negative).
shiftL# :: Word# -> Int# -> Word#
a `shiftL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0##
| otherwise = a `uncheckedShiftL#` b
-- | Shift the argument right by the specified number of bits
-- (which must be non-negative).
-- The "RL" means "right, logical" (as opposed to RA for arithmetic)
-- (although an arithmetic right shift wouldn't make sense for Word#)
shiftRL# :: Word# -> Int# -> Word#
a `shiftRL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0##
| otherwise = a `uncheckedShiftRL#` b
-- | Shift the argument left by the specified number of bits
-- (which must be non-negative).
iShiftL# :: Int# -> Int# -> Int#
a `iShiftL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0#
| otherwise = a `uncheckedIShiftL#` b
-- | Shift the argument right (signed) by the specified number of bits
-- (which must be non-negative).
-- The "RA" means "right, arithmetic" (as opposed to RL for logical)
iShiftRA# :: Int# -> Int# -> Int#
a `iShiftRA#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = if isTrue# (a <# 0#)
then (-1#)
else 0#
| otherwise = a `uncheckedIShiftRA#` b
-- | Shift the argument right (unsigned) by the specified number of bits
-- (which must be non-negative).
-- The "RL" means "right, logical" (as opposed to RA for arithmetic)
iShiftRL# :: Int# -> Int# -> Int#
a `iShiftRL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0#
| otherwise = a `uncheckedIShiftRL#` b
-- Rules for C strings (the functions themselves are now in GHC.CString)
{-# RULES
"unpack" [~1] forall a . unpackCString# a = build (unpackFoldrCString# a)
"unpack-list" [1] forall a . unpackFoldrCString# a (:) [] = unpackCString# a
"unpack-append" forall a n . unpackFoldrCString# a (:) n = unpackAppendCString# a n
-- There's a built-in rule (in PrelRules.hs) for
-- unpackFoldr "foo" c (unpackFoldr "baz" c n) = unpackFoldr "foobaz" c n
#-}
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index eac53ba..f641299 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -1,638 +1,641 @@
# Changelog for [`base` package](http://hackage.haskell.org/package/base)
## 4.11.0.0 *TBA*
* Bundled with GHC *TBA*
* Add `Alternative` instance for `ZipList` (#13520)
* Add instances `Num`, `Functor`, `Applicative`, `Monad`, `Semigroup`
and `Monoid` for `Data.Ord.Down` (#13097).
* Add `Semigroup` instance for `EventLifetime`.
* Make `Semigroup` a superclass of `Monoid`;
export `Semigroup` from `Prelude`; remove `Monoid` reexport
from `Data.Semigroup` (#14191).
+ * Generalise `instance Monoid a => Monoid (Maybe a)` to
+ `instance Semigroup a => Monoid (Maybe a)`.
+
* Add `infixl 9 !!` declaration for `Data.List.NonEmpty.!!`
* Add `<&>` operator to `Data.Functor` (#14029)
* Remove the deprecated `Typeable{1..7}` type synonyms (#14047)
* Make `Data.Type.Equality.==` a closed type family. It now works for all
kinds out of the box. Any modules that previously declared instances of this
family will need to remove them. Whereas the previous definition was somewhat
ad hoc, the behavior is now completely uniform. As a result, some applications
that used to reduce no longer do, and conversely. Most notably, `(==)` no
longer treats the `*`, `j -> k`, or `()` kinds specially; equality is
tested structurally in all cases.
* Add instances `Semigroup` and `Monoid` for `Control.Monad.ST` (#14107).
* The `Read` instances for `Proxy`, `Coercion`, `(:~:)`, `(:~~:)`, and `U1`
now ignore the parsing precedence. The effect of this is that `read` will
be able to successfully parse more strings containing `"Proxy"` _et al._
without surrounding parentheses (e.g., `"Thing Proxy"`) (#12874).
* Add `iterate'`, a strict version of `iterate`, to `Data.List`
and `Data.OldList` (#3474)
* Add `Data` instances for `IntPtr` and `WordPtr` (#13115)
* Add missing `MonadFail` instance for `Control.Monad.Strict.ST.ST`
## 4.10.0.0 *April 2017*
* Bundled with GHC *TBA*
* `Data.Type.Bool.Not` given a type family dependency (#12057).
* `Foreign.Ptr` now exports the constructors for `IntPtr` and `WordPtr`
(#11983)
* `Generic1`, as well as the associated datatypes and typeclasses in
`GHC.Generics`, are now poly-kinded (#10604)
* `New modules `Data.Bifoldable` and `Data.Bitraversable` (previously defined
in the `bifunctors` package) (#10448)
* `Data.Either` now provides `fromLeft` and `fromRight` (#12402)
* `Data.Type.Coercion` now provides `gcoerceWith` (#12493)
* New methods `liftReadList(2)` and `liftReadListPrec(2)` in the
`Read1`/`Read2` classes that are defined in terms of `ReadPrec` instead of
`ReadS`, as well as related combinators, have been added to
`Data.Functor.Classes` (#12358)
* Add `Semigroup` instance for `IO`, as well as for `Event` and `Lifetime`
from `GHC.Event` (#12464)
* Add `Data` instance for `Const` (#12438)
* Added `Eq1`, `Ord1`, `Read1` and `Show1` instances for `NonEmpty`.
* Add wrappers for `blksize_t`, `blkcnt_t`, `clockid_t`, `fsblkcnt_t`,
`fsfilcnt_t`, `id_t`, `key_t`, and `timer_t` to System.Posix.Types (#12795)
* Add `CBool`, a wrapper around C's `bool` type, to `Foreign.C.Types`
(#13136)
* Raw buffer operations in `GHC.IO.FD` are now strict in the buffer, offset, and length operations (#9696)
* Add `plusForeignPtr` to `Foreign.ForeignPtr`.
* Add `type family AppendSymbol (m :: Symbol) (n :: Symbol) :: Symbol` to `GHC.TypeLits`
(#12162)
* Add `GHC.TypeNats` module with `Natural`-based `KnownNat`. The `Nat`
operations in `GHC.TypeLits` are a thin compatibility layer on top.
Note: the `KnownNat` evidence is changed from an `Integer` to a `Natural`.
* The type of `asProxyTypeOf` in `Data.Proxy` has been generalized (#12805)
* `liftA2` is now a method of the `Applicative` class. `liftA2` and
`<*>` each have a default implementation based on the other. Various
library functions have been updated to use `liftA2` where it might offer
some benefit. `liftA2` is not yet in the `Prelude`, and must currently be
imported from `Control.Applicative`. It is likely to be added to the
`Prelude` in the future. (#13191)
* A new module, `Type.Reflection`, exposing GHC's new type-indexed type
representation mechanism is now provided.
* `Data.Dynamic` now exports the `Dyn` data constructor, enabled by the new
type-indexed type representation mechanism.
* `Data.Type.Equality` now provides a kind heterogeneous type equality
evidence type, `(:~~:)`.
* The `CostCentresXML` constructor of `GHC.RTS.Flags.DoCostCentres` has been
replaced by `CostCentresJSON` due to the new JSON export format supported by
the cost centre profiler.
* The `ErrorCall` pattern synonym has been given a `COMPLETE` pragma so that
functions which solely match again `ErrorCall` do not produce
non-exhaustive pattern-match warnings (#8779)
* Change the implementations of `maximumBy` and `minimumBy` from
`Data.Foldable` to use `foldl1` instead of `foldr1`. This makes them run
in constant space when applied to lists. (#10830)
* `mkFunTy`, `mkAppTy`, and `mkTyConApp` from `Data.Typeable` no longer exist.
This functionality is superceded by the interfaces provided by
`Type.Reflection`.
* `mkTyCon3` is no longer exported by `Data.Typeable`. This function is
replaced by `Type.Reflection.Unsafe.mkTyCon`.
* `Data.List.NonEmpty.unfold` has been deprecated in favor of `unfoldr`,
which is functionally equivalent.
## 4.9.0.0 *May 2016*
* Bundled with GHC 8.0
* `error` and `undefined` now print a partial stack-trace alongside the error message.
* New `errorWithoutStackTrace` function throws an error without printing the stack trace.
* The restore operation provided by `mask` and `uninterruptibleMask` now
restores the previous masking state whatever the current masking state is.
* New `GHC.Generics.packageName` operation
* Redesigned `GHC.Stack.CallStack` data type. As a result, `CallStack`'s
`Show` instance produces different output, and `CallStack` no longer has an
`Eq` instance.
* New `GHC.Generics.packageName` operation
* New `GHC.Stack.Types` module now contains the definition of
`CallStack` and `SrcLoc`
* New `GHC.Stack.Types.emptyCallStack` function builds an empty `CallStack`
* New `GHC.Stack.Types.freezeCallStack` function freezes a `CallStack` preventing future `pushCallStack` operations from having any effect
* New `GHC.Stack.Types.pushCallStack` function pushes a call-site onto a `CallStack`
* New `GHC.Stack.Types.fromCallSiteList` function creates a `CallStack` from
a list of call-sites (i.e., `[(String, SrcLoc)]`)
* `GHC.SrcLoc` has been removed
* `GHC.Stack.showCallStack` and `GHC.SrcLoc.showSrcLoc` are now called
`GHC.Stack.prettyCallStack` and `GHC.Stack.prettySrcLoc` respectively
* add `Data.List.NonEmpty` and `Data.Semigroup` (to become
super-class of `Monoid` in the future). These modules were
provided by the `semigroups` package previously. (#10365)
* Add `selSourceUnpackedness`, `selSourceStrictness`, and
`selDecidedStrictness`, three functions which look up strictness
information of a field in a data constructor, to the `Selector` type class
in `GHC.Generics` (#10716)
* Add `URec`, `UAddr`, `UChar`, `UDouble`, `UFloat`, `UInt`, and `UWord` to
`GHC.Generics` as part of making GHC generics capable of handling
unlifted types (#10868)
* The `Eq`, `Ord`, `Read`, and `Show` instances for `U1` now use lazier
pattern-matching
* Keep `shift{L,R}` on `Integer` with negative shift-arguments from
segfaulting (#10571)
* Add `forkOSWithUnmask` to `Control.Concurrent`, which is like
`forkIOWithUnmask`, but the child is run in a bound thread.
* The `MINIMAL` definition of `Arrow` is now `arr AND (first OR (***))`.
* The `MINIMAL` definition of `ArrowChoice` is now `left OR (+++)`.
* Exported `GiveGCStats`, `DoCostCentres`, `DoHeapProfile`, `DoTrace`,
`RtsTime`, and `RtsNat` from `GHC.RTS.Flags`
* New function `GHC.IO.interruptible` used to correctly implement
`Control.Exception.allowInterrupt` (#9516)
* Made `PatternMatchFail`, `RecSelError`, `RecConError`, `RecUpdError`,
`NoMethodError`, and `AssertionFailed` newtypes (#10738)
* New module `Control.Monad.IO.Class` (previously provided by `transformers`
package). (#10773)
* New modules `Data.Functor.Classes`, `Data.Functor.Compose`,
`Data.Functor.Product`, and `Data.Functor.Sum` (previously provided by
`transformers` package). (#11135)
* New instances for `Proxy`: `Eq1`, `Ord1`, `Show1`, `Read1`. All
of the classes are from `Data.Functor.Classes` (#11756).
* New module `Control.Monad.Fail` providing new `MonadFail(fail)`
class (#10751)
* Add `GHC.TypeLits.TypeError` and `ErrorMessage` to allow users
to define custom compile-time error messages.
* Redesign `GHC.Generics` to use type-level literals to represent the
metadata of generic representation types (#9766)
* The `IsString` instance for `[Char]` has been modified to eliminate
ambiguity arising from overloaded strings and functions like `(++)`.
* Move `Const` from `Control.Applicative` to its own module in
`Data.Functor.Const`. (#11135)
* Re-export `Const` from `Control.Applicative` for backwards compatibility.
* Expand `Floating` class to include operations that allow for better
precision: `log1p`, `expm1`, `log1pexp` and `log1mexp`. These are not
available from `Prelude`, but the full class is exported from `Numeric`.
* New `Control.Exception.TypeError` datatype, which is thrown when an
expression fails to typecheck when run using `-fdefer-type-errors` (#10284)
### New instances
* `Alt`, `Dual`, `First`, `Last`, `Product`, and `Sum` now have `Data`,
`MonadZip`, and `MonadFix` instances
* The datatypes in `GHC.Generics` now have `Enum`, `Bounded`, `Ix`,
`Functor`, `Applicative`, `Monad`, `MonadFix`, `MonadPlus`, `MonadZip`,
`Foldable`, `Foldable`, `Traversable`, `Generic1`, and `Data` instances
as appropriate.
* `Maybe` now has a `MonadZip` instance
* `All` and `Any` now have `Data` instances
* `Dual`, `First`, `Last`, `Product`, and `Sum` now have `Foldable` and
`Traversable` instances
* `Dual`, `Product`, and `Sum` now have `Functor`, `Applicative`, and
`Monad` instances
* `(,) a` now has a `Monad` instance
* `ZipList` now has `Foldable` and `Traversable` instances
* `Identity` now has `Semigroup` and `Monoid` instances
* `Identity` and `Const` now have `Bits`, `Bounded`, `Enum`, `FiniteBits`,
`Floating`, `Fractional`, `Integral`, `IsString`, `Ix`, `Num`, `Real`,
`RealFloat`, `RealFrac` and `Storable` instances. (#11210, #11790)
* `()` now has a `Storable` instance
* `Complex` now has `Generic`, `Generic1`, `Functor`, `Foldable`, `Traversable`,
`Applicative`, and `Monad` instances
* `System.Exit.ExitCode` now has a `Generic` instance
* `Data.Version.Version` now has a `Generic` instance
* `IO` now has a `Monoid` instance
* Add `MonadPlus IO` and `Alternative IO` instances
(previously orphans in `transformers`) (#10755)
* `CallStack` now has an `IsList` instance
* The field `spInfoName` of `GHC.StaticPtr.StaticPtrInfo` has been removed.
The value is no longer available when constructing the `StaticPtr`.
* `VecElem` and `VecCount` now have `Enum` and `Bounded` instances.
### Generalizations
* Generalize `Debug.Trace.{traceM, traceShowM}` from `Monad` to `Applicative`
(#10023)
* Redundant typeclass constraints have been removed:
- `Data.Ratio.{denominator,numerator}` have no `Integral` constraint anymore
- **TODO**
* Generalise `forever` from `Monad` to `Applicative`
* Generalize `filterM`, `mapAndUnzipM`, `zipWithM`, `zipWithM_`, `replicateM`,
`replicateM_` from `Monad` to `Applicative` (#10168)
* The `Generic` instance for `Proxy` is now poly-kinded (#10775)
* Enable `PolyKinds` in the `Data.Functor.Const` module to give `Const`
the kind `* -> k -> *`. (#10039)
## 4.8.2.0 *Oct 2015*
* Bundled with GHC 7.10.3
* The restore operation provided by `mask` and `uninterruptibleMask` now
restores the previous masking state whatever the current masking state is.
* Exported `GiveGCStats`, `DoCostCentres`, `DoHeapProfile`, `DoTrace`,
`RtsTime`, and `RtsNat` from `GHC.RTS.Flags`
## 4.8.1.0 *Jul 2015*
* Bundled with GHC 7.10.2
* `Lifetime` is now exported from `GHC.Event`
* Implicit-parameter based source location support exposed in `GHC.SrcLoc` and `GHC.Stack`.
See GHC User's Manual for more information.
## 4.8.0.0 *Mar 2015*
* Bundled with GHC 7.10.1
* Make `Applicative` a superclass of `Monad`
* Add reverse application operator `Data.Function.(&)`
* Add `Data.List.sortOn` sorting function
* Add `System.Exit.die`
* Deprecate `versionTags` field of `Data.Version.Version`.
Add `makeVersion :: [Int] -> Version` constructor function to aid
migration to a future `versionTags`-less `Version`.
* Add `IsList Version` instance
* Weaken RealFloat constraints on some `Data.Complex` functions
* Add `Control.Monad.(<$!>)` as a strict version of `(<$>)`
* The `Data.Monoid` module now has the `PolyKinds` extension
enabled, so that the `Monoid` instance for `Proxy` are polykinded
like `Proxy` itself is.
* Make `abs` and `signum` handle (-0.0) correctly per IEEE-754.
* Re-export `Data.Word.Word` from `Prelude`
* Add `countLeadingZeros` and `countTrailingZeros` methods to
`Data.Bits.FiniteBits` class
* Add `Data.List.uncons` list destructor (#9550)
* Export `Monoid(..)` from `Prelude`
* Export `Foldable(..)` from `Prelude`
(hiding `fold`, `foldl'`, `foldr'`, and `toList`)
* Export `Traversable(..)` from `Prelude`
* Set fixity for `Data.Foldable.{elem,notElem}` to match the
conventional one set for `Data.List.{elem,notElem}` (#9610)
* Turn `toList`, `elem`, `sum`, `product`, `maximum`, and `minimum`
into `Foldable` methods (#9621)
* Replace the `Data.List`-exported functions
```
all, and, any, concat, concatMap, elem, find, product, sum,
mapAccumL, mapAccumR
```
by re-exports of their generalised `Data.Foldable`/`Data.Traversable`
counterparts. In other words, unqualified imports of `Data.List`
and `Data.Foldable`/`Data.Traversable` no longer lead to conflicting
definitions. (#9586)
* New (unofficial) module `GHC.OldList` containing only list-specialised
versions of the functions from `Data.List` (in other words, `GHC.OldList`
corresponds to `base-4.7.0.2`'s `Data.List`)
* Replace the `Control.Monad`-exported functions
```
sequence_, msum, mapM_, forM_,
forM, mapM, sequence
```
by re-exports of their generalised `Data.Foldable`/`Data.Traversable`
counterparts. In other words, unqualified imports of `Control.Monad`
and `Data.Foldable`/`Data.Traversable` no longer lead to conflicting
definitions. (#9586)
* Generalise `Control.Monad.{when,unless,guard}` from `Monad` to
`Applicative` and from `MonadPlus` to `Alternative` respectively.
* Generalise `Control.Monad.{foldM,foldM_}` to `Foldable`
* `scanr`, `mapAccumL` and `filterM` now take part in list fusion (#9355,
#9502, #9546)
* Remove deprecated `Data.OldTypeable` (#9639)
* New module `Data.Bifunctor` providing the `Bifunctor(bimap,first,second)`
class (previously defined in `bifunctors` package) (#9682)
* New module `Data.Void` providing the canonical uninhabited type `Void`
(previously defined in `void` package) (#9814)
* Update Unicode class definitions to Unicode version 7.0
* Add `Alt`, an `Alternative` wrapper, to `Data.Monoid`. (#9759)
* Add `isSubsequenceOf` to `Data.List` (#9767)
* The arguments to `==` and `eq` in `Data.List.nub` and `Data.List.nubBy`
are swapped, such that `Data.List.nubBy (<) [1,2]` now returns `[1]`
instead of `[1,2]` (#2528, #3280, #7913)
* New module `Data.Functor.Identity` (previously provided by `transformers`
package). (#9664)
* Add `scanl'`, a strictly accumulating version of `scanl`, to `Data.List`
and `Data.OldList`. (#9368)
* Add `fillBytes` to `Foreign.Marshal.Utils`.
* Add new `displayException` method to `Exception` typeclass. (#9822)
* Add `Data.Bits.toIntegralSized`, a size-checked version of
`fromIntegral`. (#9816)
* New module `Numeric.Natural` providing new `Natural` type
representing non-negative arbitrary-precision integers. The `GHC.Natural`
module exposes additional GHC-specific primitives. (#9818)
* Add `(Storable a, Integeral a) => Storable (Ratio a)` instance (#9826)
* Add `Storable a => Storable (Complex a)` instance (#9826)
* New module `GHC.RTS.Flags` that provides accessors to runtime flags.
* Expose functions for per-thread allocation counters and limits in `GHC.Conc`
disableAllocationLimit :: IO ()
enableAllocationLimit :: IO ()
getAllocationCounter :: IO Int64
setAllocationCounter :: Int64 -> IO ()
together with a new exception `AllocationLimitExceeded`.
* Make `read . show = id` for `Data.Fixed` (#9240)
* Add `calloc` and `callocBytes` to `Foreign.Marshal.Alloc`. (#9859)
* Add `callocArray` and `callocArray0` to `Foreign.Marshal.Array`. (#9859)
* Restore invariant in `Data (Ratio a)` instance (#10011)
* Add/expose `rnfTypeRep`, `rnfTyCon`, `typeRepFingerprint`, and
`tyConFingerprint` helpers to `Data.Typeable`.
* Define proper `MINIMAL` pragma for `class Ix`. (#10142)
## 4.7.0.2 *Dec 2014*
* Bundled with GHC 7.8.4
* Fix performance bug in `Data.List.inits` (#9345)
* Fix handling of null bytes in `Debug.Trace.trace` (#9395)
## 4.7.0.1 *Jul 2014*
* Bundled with GHC 7.8.3
* Unhide `Foreign.ForeignPtr` in Haddock (#8475)
* Fix recomputation of `TypeRep` in `Typeable` type-application instance
(#9203)
* Fix regression in Data.Fixed Read instance (#9231)
* Fix `fdReady` to honor `FD_SETSIZE` (#9168)
## 4.7.0.0 *Apr 2014*
* Bundled with GHC 7.8.1
* Add `/Since: 4.[4567].0.0/` Haddock annotations to entities
denoting the package version, when the given entity was introduced
(or its type signature changed in a non-compatible way)
* The `Control.Category` module now has the `PolyKinds` extension
enabled, meaning that instances of `Category` no longer need be of
kind `* -> * -> *`.
* There are now `Foldable` and `Traversable` instances for `Either a`,
`Const r`, and `(,) a`.
* There are now `Show`, `Read`, `Eq`, `Ord`, `Monoid`, `Generic`, and
`Generic1` instances for `Const`.
* There is now a `Data` instance for `Data.Version`.
* A new `Data.Bits.FiniteBits` class has been added to represent
types with fixed bit-count. The existing `Bits` class is extended
with a `bitSizeMaybe` method to replace the now obsolete
`bitsize` method.
* `Data.Bits.Bits` gained a new `zeroBits` method which completes the
`Bits` API with a direct way to introduce a value with all bits cleared.
* There are now `Bits` and `FiniteBits` instances for `Bool`.
* There are now `Eq`, `Ord`, `Show`, `Read`, `Generic`. and `Generic1`
instances for `ZipList`.
* There are now `Eq`, `Ord`, `Show` and `Read` instances for `Down`.
* There are now `Eq`, `Ord`, `Show`, `Read` and `Generic` instances
for types in GHC.Generics (`U1`, `Par1`, `Rec1`, `K1`, `M1`,
`(:+:)`, `(:*:)`, `(:.:)`).
* `Data.Monoid`: There are now `Generic` instances for `Dual`, `Endo`,
`All`, `Any`, `Sum`, `Product`, `First`, and `Last`; as well as
`Generic1` instances for `Dual`, `Sum`, `Product`, `First`, and `Last`.
* The `Data.Monoid.{Product,Sum}` newtype wrappers now have `Num` instances.
* There are now `Functor` instances for `System.Console.GetOpt`'s
`ArgOrder`, `OptDescr`, and `ArgDescr`.
* A zero-width unboxed poly-kinded `Proxy#` was added to
`GHC.Prim`. It can be used to make it so that there is no the
operational overhead for passing around proxy arguments to model
type application.
* New `Data.Proxy` module providing a concrete, poly-kinded proxy type.
* New `Data.Coerce` module which exports the new `Coercible` class
together with the `coerce` primitive which provide safe coercion
(wrt role checking) between types with same representation.
* `Control.Concurrent.MVar` has a new implementation of `readMVar`,
which fixes a long-standing bug where `readMVar` is only atomic if
there are no other threads running `putMVar`. `readMVar` now is
atomic, and is guaranteed to return the value from the first
`putMVar`. There is also a new `tryReadMVar` which is a
non-blocking version.
* New `Control.Concurrent.MVar.withMVarMasked` which executes
`IO` action with asynchronous exceptions masked in the same style
as the existing `modifyMVarMasked` and `modifyMVarMasked_`.
* New `threadWait{Read,Write}STM :: Fd -> IO (STM (), IO ())`
functions added to `Control.Concurrent` for waiting on FD
readiness with STM actions.
* Expose `Data.Fixed.Fixed`'s constructor.
* There are now byte endian-swapping primitives
`byteSwap{16,32,64}` available in `Data.Word`, which use
optimized machine instructions when available.
* `Data.Bool` now exports `bool :: a -> a -> Bool -> a`, analogously
to `maybe` and `either` in their respective modules.
* `Data.Either` now exports `isLeft, isRight :: Either a b -> Bool`.
* `Debug.Trace` now exports `traceId`, `traceShowId`, `traceM`,
and `traceShowM`.
* `Data.Functor` now exports `($>)` and `void`.
* Rewrote portions of `Text.Printf`, and made changes to `Numeric`
(added `Numeric.showFFloatAlt` and `Numeric.showGFloatAlt`) and
`GHC.Float` (added `formatRealFloatAlt`) to support it. The
rewritten version is extensible to user types, adds a "generic"
format specifier "`%v`", extends the `printf` spec to support much
of C's `printf(3)` functionality, and fixes the spurious warnings
about using `Text.Printf.printf` at `(IO a)` while ignoring the
return value. These changes were contributed by Bart Massey.
* The minimal complete definitions for all type-classes with cyclic
default implementations have been explicitly annotated with the
new `{-# MINIMAL #-}` pragma.
* `Control.Applicative.WrappedMonad`, which can be used to convert a
`Monad` to an `Applicative`, has now a
`Monad m => Monad (WrappedMonad m)` instance.
* There is now a `Generic` and a `Generic1` instance for `WrappedMonad`
and `WrappedArrow`.
* Handle `ExitFailure (-sig)` on Unix by killing process with signal `sig`.
* New module `Data.Type.Bool` providing operations on type-level booleans.
* Expose `System.Mem.performMinorGC` for triggering minor GCs.
* New `System.Environment.{set,unset}Env` for manipulating
environment variables.
* Add `Typeable` instance for `(->)` and `RealWorld`.
* Declare CPP header `` officially obsolete as GHC 7.8+
does not support hand-written `Typeable` instances anymore.
* Remove (unmaintained) Hugs98 and NHC98 specific code.
* Optimize `System.Timeout.timeout` for the threaded RTS.
* Remove deprecated functions `unsafeInterleaveST`, `unsafeIOToST`,
and `unsafeSTToIO` from `Control.Monad.ST`.
* Add a new superclass `SomeAsyncException` for all asynchronous exceptions
and makes the existing `AsyncException` and `Timeout` exception children
of `SomeAsyncException` in the hierarchy.
* Remove deprecated functions `blocked`, `unblock`, and `block` from
`Control.Exception`.
* Remove deprecated function `forkIOUnmasked` from `Control.Concurrent`.
* Remove deprecated function `unsafePerformIO` export from `Foreign`
(still available via `System.IO.Unsafe.unsafePerformIO`).
* Various fixes and other improvements (see Git history for full details).
diff --git a/testsuite/tests/ghci/scripts/T4175.stdout b/testsuite/tests/ghci/scripts/T4175.stdout
index 7b630f1..c7421b5 100644
--- a/testsuite/tests/ghci/scripts/T4175.stdout
+++ b/testsuite/tests/ghci/scripts/T4175.stdout
@@ -1,60 +1,60 @@
type family A a b :: * -- Defined at T4175.hs:7:1
type instance A (Maybe a) a = a -- Defined at T4175.hs:9:15
type instance A Int Int = () -- Defined at T4175.hs:8:15
type instance A (B a) b = () -- Defined at T4175.hs:10:15
data family B a -- Defined at T4175.hs:12:1
instance G B -- Defined at T4175.hs:34:10
type instance A (B a) b = () -- Defined at T4175.hs:10:15
data instance B () = MkB -- Defined at T4175.hs:13:15
class C a where
type family D a b :: *
-- Defined at T4175.hs:16:5
type instance D () () = Bool -- Defined at T4175.hs:22:10
type instance D Int () = String -- Defined at T4175.hs:19:10
type family E a :: *
where
E () = Bool
E Int = String
-- Defined at T4175.hs:24:1
data () = () -- Defined in ‘GHC.Tuple’
instance C () -- Defined at T4175.hs:21:10
instance Eq () -- Defined in ‘GHC.Classes’
instance Monoid () -- Defined in ‘GHC.Base’
instance Ord () -- Defined in ‘GHC.Classes’
instance Semigroup () -- Defined in ‘GHC.Base’
instance Show () -- Defined in ‘GHC.Show’
instance Read () -- Defined in ‘GHC.Read’
instance Enum () -- Defined in ‘GHC.Enum’
instance Bounded () -- Defined in ‘GHC.Enum’
type instance D () () = Bool -- Defined at T4175.hs:22:10
type instance D Int () = String -- Defined at T4175.hs:19:10
data instance B () = MkB -- Defined at T4175.hs:13:15
data Maybe a = Nothing | Just a -- Defined in ‘GHC.Base’
instance Applicative Maybe -- Defined in ‘GHC.Base’
instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Base’
instance Functor Maybe -- Defined in ‘GHC.Base’
instance Monad Maybe -- Defined in ‘GHC.Base’
-instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’
+instance Semigroup a => Monoid (Maybe a) -- Defined in ‘GHC.Base’
instance Ord a => Ord (Maybe a) -- Defined in ‘GHC.Base’
instance Semigroup a => Semigroup (Maybe a)
-- Defined in ‘GHC.Base’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
instance Read a => Read (Maybe a) -- Defined in ‘GHC.Read’
instance Foldable Maybe -- Defined in ‘Data.Foldable’
instance Traversable Maybe -- Defined in ‘Data.Traversable’
type instance A (Maybe a) a = a -- Defined at T4175.hs:9:15
data Int = I# Int# -- Defined in ‘GHC.Types’
instance C Int -- Defined at T4175.hs:18:10
instance Eq Int -- Defined in ‘GHC.Classes’
instance Ord Int -- Defined in ‘GHC.Classes’
instance Show Int -- Defined in ‘GHC.Show’
instance Read Int -- Defined in ‘GHC.Read’
instance Enum Int -- Defined in ‘GHC.Enum’
instance Num Int -- Defined in ‘GHC.Num’
instance Real Int -- Defined in ‘GHC.Real’
instance Bounded Int -- Defined in ‘GHC.Enum’
instance Integral Int -- Defined in ‘GHC.Real’
type instance D Int () = String -- Defined at T4175.hs:19:10
type instance A Int Int = () -- Defined at T4175.hs:8:15
class Z a -- Defined at T4175.hs:28:1
instance F (Z a) -- Defined at T4175.hs:31:10