Movatterモバイル変換


[0]ホーム

URL:


{-NOTA BENE: Do NOT use ($) anywhere in this module! The type of ($) isslightly 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 thismodule, because it has different types in different scenarios.This is not a problem in general, because the type ($), being wired in, is notwritten 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 modulesSo the rough structure is as follows, in (linearised) dependency orderGHC.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.hiGHC.Base        Classes: Eq, Ord, Functor, Monad                Types:   list, (), Int, Bool, Ordering, Char, StringData.Tuple      Types: tuples, plus instances for GHC.Base classesGHC.Show        Class: Show, plus instances for GHC.Base/GHC.Tup typesGHC.Enum        Class: Enum,  plus instances for GHC.Base/GHC.Tup typesData.Maybe      Type: Maybe, plus instances for GHC.Base classesGHC.List        List functionsGHC.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 NumGHC.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 RealGHC.ST  The ST monad, instances and a few helper functionsIx              Classes: Ix, plus instances for Int, Bool, Char, Integer, Ordering, tuplesGHC.Arr         Types: Array, MutableArray, MutableVar                Arrays are used by a function in GHC.FloatGHC.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.hiOther Prelude modules are much easier with fewer complex dependencies.-}{-# LANGUAGE Unsafe #-}{-# LANGUAGE CPP           , NoImplicitPrelude           , BangPatterns           , ExplicitForAll           , MagicHash           , UnboxedTuples           , ExistentialQuantification           , RankNTypes           , KindSignatures           , PolyKinds           , DataKinds  #-}-- -Wno-orphans is needed for things like:-- Orphan rule: "x# -# x#" ALWAYS forall x# :: Int# -# x# x# = 0{-# OPTIONS_GHC -Wno-orphans #-}{-# OPTIONS_HADDOCK not-home #-}------------------------------------------------------------------------------- |-- 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"moduleGHC.Base(moduleGHC.Base,moduleGHC.Classes,moduleGHC.CString,moduleGHC.Magic,moduleGHC.Types,moduleGHC.Prim,-- Re-export GHC.Prim and [boot] GHC.Err,moduleGHC.Prim.Ext,-- to avoid lots of people having tomoduleGHC.Err,-- import it explicitlymoduleGHC.Maybe)whereimportGHC.TypesimportGHC.ClassesimportGHC.CStringimportGHC.MagicimportGHC.PrimimportGHC.Prim.ExtimportGHC.ErrimportGHC.Maybeimport{-# SOURCE#-}GHC.IO(mkUserError,mplusIO)importGHC.Tuple()-- Note [Depend on GHC.Tuple]importGHC.Integer()-- Note [Depend on GHC.Integer]importGHC.Natural()-- Note [Depend on GHC.Natural]-- for 'class Semigroup'import{-# SOURCE#-}GHC.Real(Integral)import{-# SOURCE#-}Data.Semigroup.Internal(stimesDefault,stimesMaybe,stimesList,stimesIdempotentMonoid)infixr9.infixr5++infixl4<$infixl1>>,>>=infixr1=<<infixr0$,$!infixl4<*>,<*,*>,<**>default()-- Double isn't available yet{-Note [Depend on GHC.Integer]~~~~~~~~~~~~~~~~~~~~~~~~~~~~The Integer type is special because TidyPgm usesGHC.Integer.Type.mkInteger to construct Integer literal valuesCurrently it reads the interface file whether or not the currentmodule *has* any Integer literals, so it's important thatGHC.Integer.Type (in package integer-gmp or integer-simple) iscompiled before any other module.  (There's a hack in GHC to disablethis for packages ghc-prim, integer-gmp, integer-simple, which aren'tallowed to contain any Integer literals.)Likewise we implicitly need Integer when deriving things like Eqinstances.The danger is that if the build system doesn't know about the dependencyon 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 everythingelse 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 onGHC.Tuple, so we use the same rule as for Integer --- see Note [Depend onGHC.Integer] --- to explain this to the build system.  We make GHC.Basedepend on GHC.Tuple, and everything else depends on GHC.Base or Prelude.Note [Depend on GHC.Natural]~~~~~~~~~~~~~~~~~~~~~~~~~~Similar to GHC.Integer.-}#if 0-- for use when compiling GHC.Base itself doesn't workdataBool=False|TruedataOrdering=LT|EQ|GTdataChar=C#Char#typeString=[Char]dataInt=I#Int#data()=()data[]a=MkNilnotTrue=False(&&)TrueTrue=Trueotherwise=Truebuild=errorWithoutStackTrace"urk"foldr=errorWithoutStackTrace"urk"#endifinfixr6<>-- | The class of semigroups (types with an associative binary operation).---- Instances should satisfy the following:---- [Associativity] @x '<>' (y '<>' z) = (x '<>' y) '<>' z@---- @since 4.9.0.0classSemigroupawhere-- | An associative operation.---- >>> [1,2,3] <> [4,5,6]-- [1,2,3,4,5,6](<>)::a->a->a-- | Reduce a non-empty list with '<>'---- The default definition should be sufficient, but this can be-- overridden for efficiency.---- >>> import Data.List.NonEmpty-- >>> sconcat $ "Hello" :| [" ", "Haskell", "!"]-- "Hello Haskell!"sconcat::NonEmptya->asconcat(aa:|[a]as)=a -> [a] -> aforall t. Semigroup t => t -> [t] -> tgoaa[a]aswherego :: t -> [t] -> tgotb(tc:[t]cs)=tbt -> t -> tforall a. Semigroup a => a -> a -> a<>t -> [t] -> tgotc[t]csgotb[]=tb-- | 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 \(\mathcal{O}(1)\) by-- picking @stimes = 'Data.Semigroup.stimesIdempotent'@ or @stimes =-- 'stimesIdempotentMonoid'@ respectively.---- >>> stimes 4 [1]-- [1,1,1,1]stimes::Integralb=>b->a->astimes=b -> a -> aforall b a. (Integral b, Semigroup a) => b -> a -> astimesDefault-- | The class of monoids (types with an associative binary operation that-- has an identity).  Instances should satisfy the following:---- [Right identity] @x '<>' 'mempty' = x@-- [Left identity]  @'mempty' '<>' x = x@-- [Associativity]  @x '<>' (y '<>' z) = (x '<>' y) '<>' z@ ('Semigroup' law)-- [Concatenation]  @'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. 'Data.Semigroup.Sum' and 'Data.Semigroup.Product'.---- __NOTE__: 'Semigroup' is a superclass of 'Monoid' since /base-4.11.0.0/.classSemigroupa=>Monoidawhere-- | Identity of 'mappend'---- >>> "Hello world" <> mempty-- "Hello world"mempty::a-- | An associative operation---- __NOTE__: This method is redundant and has the default-- implementation @'mappend' = ('<>')@ since /base-4.11.0.0/.-- Should it be implemented manually, since 'mappend' is a synonym for-- ('<>'), it is expected that the two functions are defined the same-- way. In a future GHC release 'mappend' will be removed from 'Monoid'.mappend::a->a->amappend=a -> a -> aforall a. Semigroup a => a -> a -> a(<>){-# INLINEmappend#-}-- | 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 ["Hello", " ", "Haskell", "!"]-- "Hello Haskell!"mconcat::[a]->amconcat=(a -> a -> a) -> a -> [a] -> aforall a b. (a -> b -> b) -> b -> [a] -> bfoldra -> a -> aforall a. Monoid a => a -> a -> amappendaforall a. Monoid a => amempty-- | @since 4.9.0.0instanceSemigroup[a]where<> :: [a] -> [a] -> [a](<>)=[a] -> [a] -> [a]forall a. [a] -> [a] -> [a](++){-# INLINE(<>)#-}stimes :: b -> [a] -> [a]stimes=b -> [a] -> [a]forall b a. Integral b => b -> [a] -> [a]stimesList-- | @since 2.01instanceMonoid[a]where{-# INLINEmempty#-}mempty :: [a]mempty=[]{-# INLINEmconcat#-}mconcat :: [[a]] -> [a]mconcat[[a]]xss=[ax|[a]xs<-[[a]]xss,ax<-[a]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 xsSimilarly, mconcat for lists is just concat. Here in Base, however, we don'thave concatMap, and we'll refrain from adding it here so it won't have to behidden in imports. Instead, we use GHC's list comprehension desugaringmechanism to define mconcat and the Applicative and Monad instances for lists.We mark them INLINE because the inliner is not generally too keen to inlinebuild forms such as the ones these desugar to without our insistence.  Definingthese using list comprehensions instead of foldr has an additional potentialbenefit, as described in compiler/deSugar/DsListComp.hs: if optimizationsneeded to make foldr/build forms efficient are turned off, we'll get reasonablyefficient translations anyway.-}-- | @since 4.9.0.0instanceSemigroup(NonEmptya)where(aa:|[a]as)<> :: NonEmpty a -> NonEmpty a -> NonEmpty a<>~(ab:|[a]bs)=aaa -> [a] -> NonEmpty aforall a. a -> [a] -> NonEmpty a:|([a]as[a] -> [a] -> [a]forall a. [a] -> [a] -> [a]++aba -> [a] -> [a]forall a. a -> [a] -> [a]:[a]bs)-- | @since 4.9.0.0instanceSemigroupb=>Semigroup(a->b)wherea -> bf<> :: (a -> b) -> (a -> b) -> a -> b<>a -> bg=\ax->a -> bfaxb -> b -> bforall a. Semigroup a => a -> a -> a<>a -> bgaxstimes :: b -> (a -> b) -> a -> bstimesbna -> bfae=b -> b -> bforall a b. (Semigroup a, Integral b) => b -> a -> astimesbn(a -> bfae)-- | @since 2.01instanceMonoidb=>Monoid(a->b)wheremempty :: a -> bmemptya_=bforall a. Monoid a => amempty-- | @since 4.9.0.0instanceSemigroup()where()_<> :: () -> () -> ()<>()_=()sconcat :: NonEmpty () -> ()sconcatNonEmpty ()_=()stimes :: b -> () -> ()stimesb_()_=()-- | @since 2.01instanceMonoid()where-- Should it be strict?mempty :: ()mempty=()mconcat :: [()] -> ()mconcat[()]_=()-- | @since 4.9.0.0instance(Semigroupa,Semigroupb)=>Semigroup(a,b)where(aa,bb)<> :: (a, b) -> (a, b) -> (a, b)<>(aa',bb')=(aaa -> a -> aforall a. Semigroup a => a -> a -> a<>aa',bbb -> b -> bforall a. Semigroup a => a -> a -> a<>bb')stimes :: b -> (a, b) -> (a, b)stimesbn(aa,bb)=(b -> a -> aforall a b. (Semigroup a, Integral b) => b -> a -> astimesbnaa,b -> b -> bforall a b. (Semigroup a, Integral b) => b -> a -> astimesbnbb)-- | @since 2.01instance(Monoida,Monoidb)=>Monoid(a,b)wheremempty :: (a, b)mempty=(aforall a. Monoid a => amempty,bforall a. Monoid a => amempty)-- | @since 4.9.0.0instance(Semigroupa,Semigroupb,Semigroupc)=>Semigroup(a,b,c)where(aa,bb,cc)<> :: (a, b, c) -> (a, b, c) -> (a, b, c)<>(aa',bb',cc')=(aaa -> a -> aforall a. Semigroup a => a -> a -> a<>aa',bbb -> b -> bforall a. Semigroup a => a -> a -> a<>bb',ccc -> c -> cforall a. Semigroup a => a -> a -> a<>cc')stimes :: b -> (a, b, c) -> (a, b, c)stimesbn(aa,bb,cc)=(b -> a -> aforall a b. (Semigroup a, Integral b) => b -> a -> astimesbnaa,b -> b -> bforall a b. (Semigroup a, Integral b) => b -> a -> astimesbnbb,b -> c -> cforall a b. (Semigroup a, Integral b) => b -> a -> astimesbncc)-- | @since 2.01instance(Monoida,Monoidb,Monoidc)=>Monoid(a,b,c)wheremempty :: (a, b, c)mempty=(aforall a. Monoid a => amempty,bforall a. Monoid a => amempty,cforall a. Monoid a => amempty)-- | @since 4.9.0.0instance(Semigroupa,Semigroupb,Semigroupc,Semigroupd)=>Semigroup(a,b,c,d)where(aa,bb,cc,dd)<> :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d)<>(aa',bb',cc',dd')=(aaa -> a -> aforall a. Semigroup a => a -> a -> a<>aa',bbb -> b -> bforall a. Semigroup a => a -> a -> a<>bb',ccc -> c -> cforall a. Semigroup a => a -> a -> a<>cc',ddd -> d -> dforall a. Semigroup a => a -> a -> a<>dd')stimes :: b -> (a, b, c, d) -> (a, b, c, d)stimesbn(aa,bb,cc,dd)=(b -> a -> aforall a b. (Semigroup a, Integral b) => b -> a -> astimesbnaa,b -> b -> bforall a b. (Semigroup a, Integral b) => b -> a -> astimesbnbb,b -> c -> cforall a b. (Semigroup a, Integral b) => b -> a -> astimesbncc,b -> d -> dforall a b. (Semigroup a, Integral b) => b -> a -> astimesbndd)-- | @since 2.01instance(Monoida,Monoidb,Monoidc,Monoidd)=>Monoid(a,b,c,d)wheremempty :: (a, b, c, d)mempty=(aforall a. Monoid a => amempty,bforall a. Monoid a => amempty,cforall a. Monoid a => amempty,dforall a. Monoid a => amempty)-- | @since 4.9.0.0instance(Semigroupa,Semigroupb,Semigroupc,Semigroupd,Semigroupe)=>Semigroup(a,b,c,d,e)where(aa,bb,cc,dd,ee)<> :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e)<>(aa',bb',cc',dd',ee')=(aaa -> a -> aforall a. Semigroup a => a -> a -> a<>aa',bbb -> b -> bforall a. Semigroup a => a -> a -> a<>bb',ccc -> c -> cforall a. Semigroup a => a -> a -> a<>cc',ddd -> d -> dforall a. Semigroup a => a -> a -> a<>dd',eee -> e -> eforall a. Semigroup a => a -> a -> a<>ee')stimes :: b -> (a, b, c, d, e) -> (a, b, c, d, e)stimesbn(aa,bb,cc,dd,ee)=(b -> a -> aforall a b. (Semigroup a, Integral b) => b -> a -> astimesbnaa,b -> b -> bforall a b. (Semigroup a, Integral b) => b -> a -> astimesbnbb,b -> c -> cforall a b. (Semigroup a, Integral b) => b -> a -> astimesbncc,b -> d -> dforall a b. (Semigroup a, Integral b) => b -> a -> astimesbndd,b -> e -> eforall a b. (Semigroup a, Integral b) => b -> a -> astimesbnee)-- | @since 2.01instance(Monoida,Monoidb,Monoidc,Monoidd,Monoide)=>Monoid(a,b,c,d,e)wheremempty :: (a, b, c, d, e)mempty=(aforall a. Monoid a => amempty,bforall a. Monoid a => amempty,cforall a. Monoid a => amempty,dforall a. Monoid a => amempty,eforall a. Monoid a => amempty)-- | @since 4.9.0.0instanceSemigroupOrderingwhereOrderingLT<> :: Ordering -> Ordering -> Ordering<>Ordering_=OrderingLTOrderingEQ<>Orderingy=OrderingyOrderingGT<>Ordering_=OrderingGTstimes :: b -> Ordering -> Orderingstimes=b -> Ordering -> Orderingforall b a. (Integral b, Monoid a) => b -> a -> astimesIdempotentMonoid-- lexicographical ordering-- | @since 2.01instanceMonoidOrderingwheremempty :: Orderingmempty=OrderingEQ-- | @since 4.9.0.0instanceSemigroupa=>Semigroup(Maybea)whereMaybe aNothing<> :: Maybe a -> Maybe a -> Maybe a<>Maybe ab=Maybe abMaybe aa<>Maybe aNothing=Maybe aaJustaa<>Justab=a -> Maybe aforall a. a -> Maybe aJust(aaa -> a -> aforall a. Semigroup a => a -> a -> a<>ab)stimes :: b -> Maybe a -> Maybe astimes=b -> Maybe a -> Maybe aforall b a. (Integral b, Semigroup a) => b -> Maybe a -> Maybe astimesMaybe-- | Lift a semigroup into 'Maybe' forming a 'Monoid' according to-- <http://en.wikipedia.org/wiki/Monoid>: \"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 4.11.0/: constraint on inner @a@ value generalised from-- 'Monoid' to 'Semigroup'.---- @since 2.01instanceSemigroupa=>Monoid(Maybea)wheremempty :: Maybe amempty=Maybe aforall a. Maybe aNothing-- | 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.01instanceMonoida=>Applicative((,)a)wherepure :: a -> (a, a)pureax=(aforall a. Monoid a => amempty,ax)(au,a -> bf)<*> :: (a, a -> b) -> (a, a) -> (a, b)<*>(av,ax)=(aua -> a -> aforall a. Semigroup a => a -> a -> a<>av,a -> bfax)liftA2 :: (a -> b -> c) -> (a, a) -> (a, b) -> (a, c)liftA2a -> b -> cf(au,ax)(av,by)=(aua -> a -> aforall a. Semigroup a => a -> a -> a<>av,a -> b -> cfaxby)-- | @since 4.9.0.0instanceMonoida=>Monad((,)a)where(au,aa)>>= :: (a, a) -> (a -> (a, b)) -> (a, b)>>=a -> (a, b)k=casea -> (a, b)kaaof(av,bb)->(aua -> a -> aforall a. Semigroup a => a -> a -> a<>av,bb)-- | @since 4.14.0.0instanceFunctor((,,)ab)wherefmap :: (a -> b) -> (a, b, a) -> (a, b, b)fmapa -> bf(aa,bb,ac)=(aa,bb,a -> bfac)-- | @since 4.14.0.0instance(Monoida,Monoidb)=>Applicative((,,)ab)wherepure :: a -> (a, b, a)pureax=(aforall a. Monoid a => amempty,bforall a. Monoid a => amempty,ax)(aa,bb,a -> bf)<*> :: (a, b, a -> b) -> (a, b, a) -> (a, b, b)<*>(aa',bb',ax)=(aaa -> a -> aforall a. Semigroup a => a -> a -> a<>aa',bbb -> b -> bforall a. Semigroup a => a -> a -> a<>bb',a -> bfax)-- | @since 4.14.0.0instance(Monoida,Monoidb)=>Monad((,,)ab)where(au,bv,aa)>>= :: (a, b, a) -> (a -> (a, b, b)) -> (a, b, b)>>=a -> (a, b, b)k=casea -> (a, b, b)kaaof(au',bv',bb)->(aua -> a -> aforall a. Semigroup a => a -> a -> a<>au',bvb -> b -> bforall a. Semigroup a => a -> a -> a<>bv',bb)-- | @since 4.14.0.0instanceFunctor((,,,)abc)wherefmap :: (a -> b) -> (a, b, c, a) -> (a, b, c, b)fmapa -> bf(aa,bb,cc,ad)=(aa,bb,cc,a -> bfad)-- | @since 4.14.0.0instance(Monoida,Monoidb,Monoidc)=>Applicative((,,,)abc)wherepure :: a -> (a, b, c, a)pureax=(aforall a. Monoid a => amempty,bforall a. Monoid a => amempty,cforall a. Monoid a => amempty,ax)(aa,bb,cc,a -> bf)<*> :: (a, b, c, a -> b) -> (a, b, c, a) -> (a, b, c, b)<*>(aa',bb',cc',ax)=(aaa -> a -> aforall a. Semigroup a => a -> a -> a<>aa',bbb -> b -> bforall a. Semigroup a => a -> a -> a<>bb',ccc -> c -> cforall a. Semigroup a => a -> a -> a<>cc',a -> bfax)-- | @since 4.14.0.0instance(Monoida,Monoidb,Monoidc)=>Monad((,,,)abc)where(au,bv,cw,aa)>>= :: (a, b, c, a) -> (a -> (a, b, c, b)) -> (a, b, c, b)>>=a -> (a, b, c, b)k=casea -> (a, b, c, b)kaaof(au',bv',cw',bb)->(aua -> a -> aforall a. Semigroup a => a -> a -> a<>au',bvb -> b -> bforall a. Semigroup a => a -> a -> a<>bv',cwc -> c -> cforall a. Semigroup a => a -> a -> a<>cw',bb)-- | @since 4.10.0.0instanceSemigroupa=>Semigroup(IOa)where<> :: IO a -> IO a -> IO a(<>)=(a -> a -> a) -> IO a -> IO a -> IO aforall (f :: * -> *) a b c.Applicative f =>(a -> b -> c) -> f a -> f b -> f cliftA2a -> a -> aforall a. Semigroup a => a -> a -> a(<>)-- | @since 4.9.0.0instanceMonoida=>Monoid(IOa)wheremempty :: IO amempty=a -> IO aforall (f :: * -> *) a. Applicative f => a -> f apureaforall a. Monoid a => amempty{- | A type @f@ is a Functor if it provides a function @fmap@ which, given any types @a@ and @b@lets you apply any function from @(a -> b)@ to turn an @f a@ into an @f b@, preserving thestructure of @f@. Furthermore @f@ needs to adhere to the following:[Identity]    @'fmap' 'id' == 'id'@[Composition] @'fmap' (f . g) == 'fmap' f . 'fmap' g@Note, that the second law follows from the free theorem of the type 'fmap' andthe first law, so you need only check that the former condition holds.-}classFunctorfwhere-- | Using @ApplicativeDo@: \'@'fmap' f as@\' can be understood as-- the @do@ expression---- @-- do a <- as--    pure (f a)-- @---- with an inferred @Functor@ constraint.fmap::(a->b)->fa->fb-- | 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.---- Using @ApplicativeDo@: \'@a '<$' bs@\' can be understood as the-- @do@ expression---- @-- do bs--    pure a-- @---- with an inferred @Functor@ constraint.(<$)::a->fb->fa(<$)=(b -> a) -> f b -> f aforall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f bfmap((b -> a) -> f b -> f a) -> (a -> b -> a) -> a -> f b -> f aforall b c a. (b -> c) -> (a -> b) -> a -> c.a -> b -> aforall a b. a -> b -> aconst-- | 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 'Prelude.<$>' 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'@----   * @m1 '<*>' m2 = m1 '>>=' (\x1 -> m2 '>>=' (\x2 -> 'return' (x1 x2)))@----   * @('*>') = ('>>')@---- (which implies that 'pure' and '<*>' satisfy the applicative functor laws).classFunctorf=>Applicativefwhere{-# MINIMALpure,((<*>)|liftA2)#-}-- | Lift a value.pure::a->fa-- | Sequential application.---- A few functors support an implementation of '<*>' that is more-- efficient than the default one.---- Using @ApplicativeDo@: \'@fs '<*>' as@\' can be understood as-- the @do@ expression---- @-- do f <- fs--    a <- as--    pure (f a)-- @(<*>)::f(a->b)->fa->fb(<*>)=((a -> b) -> a -> b) -> f (a -> b) -> f a -> f bforall (f :: * -> *) a b c.Applicative f =>(a -> b -> c) -> f a -> f b -> f cliftA2(a -> b) -> a -> bforall a. a -> aid-- | 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 '<*>'.---- This became a typeclass method in 4.10.0.0. Prior to that, it was-- a function defined in terms of '<*>' and 'fmap'.---- Using @ApplicativeDo@: \'@'liftA2' f as bs@\' can be understood-- as the @do@ expression---- @-- do a <- as--    b <- bs--    pure (f a b)-- @liftA2::(a->b->c)->fa->fb->fcliftA2a -> b -> cff ax=f (b -> c) -> f b -> f cforall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b(<*>)((a -> b -> c) -> f a -> f (b -> c)forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f bfmapa -> b -> cff ax)-- | Sequence actions, discarding the value of the first argument.---- \'@as '*>' bs@\' can be understood as the @do@ expression---- @-- do as--    bs-- @---- This is a tad complicated for our @ApplicativeDo@ extension-- which will give it a @Monad@ constraint. For an @Applicative@-- constraint we write it of the form---- @-- do _ <- as--    b <- bs--    pure b-- @(*>)::fa->fb->fbf aa1*>f ba2=(b -> bforall a. a -> aid(b -> b) -> f a -> f (b -> b)forall (f :: * -> *) a b. Functor f => a -> f b -> f a<$f aa1)f (b -> b) -> f b -> f bforall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b<*>f ba2-- 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.---- Using @ApplicativeDo@: \'@as '<*' bs@\' can be understood as-- the @do@ expression---- @-- do a <- as--    bs--    pure a-- @(<*)::fa->fb->fa(<*)=(a -> b -> a) -> f a -> f b -> f aforall (f :: * -> *) a b c.Applicative f =>(a -> b -> c) -> f a -> f b -> f cliftA2a -> b -> aforall a b. a -> b -> aconst-- | A variant of '<*>' with the arguments reversed.---- Using @ApplicativeDo@: \'@as '<**>' fs@\' can be understood as the-- @do@ expression---- @-- do a <- as--    f <- fs--    pure (f a)-- @(<**>)::Applicativef=>fa->f(a->b)->fb<**> :: f a -> f (a -> b) -> f b(<**>)=(a -> (a -> b) -> b) -> f a -> f (a -> b) -> f bforall (f :: * -> *) a b c.Applicative f =>(a -> b -> c) -> f a -> f b -> f cliftA2(\aaa -> bf->a -> bfaa)-- 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.---- | Using @ApplicativeDo@: \'@'liftA' f as@\' can be understood as the-- @do@ expression------ @-- do a <- as--    pure (f a)-- @---- with an inferred @Functor@ constraint, weaker than @Applicative@.liftA::Applicativef=>(a->b)->fa->fbliftA :: (a -> b) -> f a -> f bliftAa -> bff aa=(a -> b) -> f (a -> b)forall (f :: * -> *) a. Applicative f => a -> f apurea -> bff (a -> b) -> f a -> f bforall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b<*>f aa-- Caution: since this may be used for `fmap`, we can't use the obvious-- definition of liftA = fmap.-- | Lift a ternary function to actions.---- Using @ApplicativeDo@: \'@'liftA3' f as bs cs@\' can be understood-- as the @do@ expression---- @-- do a <- as--    b <- bs--    c <- cs--    pure (f a b c)-- @liftA3::Applicativef=>(a->b->c->d)->fa->fb->fc->fdliftA3 :: (a -> b -> c -> d) -> f a -> f b -> f c -> f dliftA3a -> b -> c -> dff aaf bbf cc=(a -> b -> c -> d) -> f a -> f b -> f (c -> d)forall (f :: * -> *) a b c.Applicative f =>(a -> b -> c) -> f a -> f b -> f cliftA2a -> b -> c -> dff aaf bbf (c -> d) -> f c -> f dforall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b<*>f cc{-# INLINABLEliftA#-}{-# SPECIALISEliftA::(a1->r)->IOa1->IOr#-}{-# SPECIALISEliftA::(a1->r)->Maybea1->Mayber#-}{-# INLINABLEliftA3#-}{-# SPECIALISEliftA3::(a1->a2->a3->r)->IOa1->IOa2->IOa3->IOr#-}{-# SPECIALISEliftA3::(a1->a2->a3->r)->Maybea1->Maybea2->Maybea3->Mayber#-}-- | 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' bss@\' can be understood as the @do@ expression---- @-- do bs <- bss--    bs-- @---- ==== __Examples__---- A common use of 'join' is to run an 'IO' computation returned from-- an 'GHC.Conc.STM' transaction, since 'GHC.Conc.STM' transactions-- can't perform 'IO' directly. Recall that---- @-- 'GHC.Conc.atomically' :: STM a -> IO a-- @---- is used to run 'GHC.Conc.STM' transactions atomically. So, by-- specializing the types of 'GHC.Conc.atomically' and 'join' to---- @-- 'GHC.Conc.atomically' :: STM (IO b) -> IO (IO b)-- 'join'       :: IO (IO b)  -> IO b-- @---- we can compose them as---- @-- 'join' . 'GHC.Conc.atomically' :: STM (IO b) -> IO b-- @---- to run an 'GHC.Conc.STM' transaction and the 'IO' action it-- returns.join::(Monadm)=>m(ma)->majoin :: m (m a) -> m ajoinm (m a)x=m (m a)xm (m a) -> (m a -> m a) -> m aforall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b>>=m a -> m aforall a. a -> aid{- | 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 tothink of a monad as an /abstract datatype/ of actions.Haskell's @do@ expressions provide a convenient syntax for writingmonadic expressions.Instances of 'Monad' should satisfy the following:[Left identity]  @'return' a '>>=' k  =  k a@[Right identity] @m '>>=' 'return'  =  m@[Associativity]  @m '>>=' (\\x -> k x '>>=' h)  =  (m '>>=' k) '>>=' h@Furthermore, the 'Monad' and 'Applicative' operations should relate as follows:* @'pure' = 'return'@* @m1 '<*>' m2 = m1 '>>=' (\x1 -> m2 '>>=' (\x2 -> 'return' (x1 x2)))@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.-}classApplicativem=>Monadmwhere-- | Sequentially compose two actions, passing any value produced-- by the first as an argument to the second.---- \'@as '>>=' bs@\' can be understood as the @do@ expression---- @-- do a <- as--    bs a-- @(>>=)::forallab.ma->(a->mb)->mb-- | Sequentially compose two actions, discarding any value produced-- by the first, like sequencing operators (such as the semicolon)-- in imperative languages.---- \'@as '>>' bs@\' can be understood as the @do@ expression---- @-- do as--    bs-- @(>>)::forallab.ma->mb->mbm am>>m bk=m amm a -> (a -> m b) -> m bforall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b>>=\a_->m bk-- See Note [Recursive bindings for Applicative/Monad]{-# INLINE(>>)#-}-- | Inject a value into the monadic type.return::a->mareturn=a -> m aforall (f :: * -> *) a. Applicative f => a -> f apure{- Note [Recursive bindings for Applicative/Monad]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~The original Applicative/Monad proposal stated that afterimplementation, 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 statedproposal, but you really shouldn't! Why? Because people tend to definesuch instances the /other/ way around: in particular, it is perfectlylegitimate to define an instance of Applicative (*>) in terms of (>>),which would lead to an infinite loop for the default implementation ofMonad! And people do this in the wild.This turned into a nasty bug that was tricky to track down, and ratherthan eliminate it everywhere upstream, it's easier to just retain theoriginal default.-}-- | Same as '>>=', but with the arguments interchanged.{-# SPECIALISE(=<<)::(a->[b])->[a]->[b]#-}(=<<)::Monadm=>(a->mb)->ma->mba -> m bf=<< :: (a -> m b) -> m a -> m b=<<m ax=m axm a -> (a -> m b) -> m bforall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b>>=a -> m bf-- | 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::(Applicativef)=>Bool->f()->f(){-# INLINABLEwhen#-}{-# SPECIALISEwhen::Bool->IO()->IO()#-}{-# SPECIALISEwhen::Bool->Maybe()->Maybe()#-}when :: Bool -> f () -> f ()whenBoolpf ()s=ifBoolpthenf ()selse() -> f ()forall (f :: * -> *) a. Applicative f => a -> f apure()-- | Evaluate each action in the sequence from left to right,-- and collect the results.sequence::Monadm=>[ma]->m[a]{-# INLINEsequence#-}sequence :: [m a] -> m [a]sequence=(m a -> m a) -> [m a] -> m [a]forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]mapMm a -> m aforall a. a -> aid-- Note: [sequence and mapM]-- | @'mapM' f@ is equivalent to @'sequence' . 'map' f@.mapM::Monadm=>(a->mb)->[a]->m[b]{-# INLINEmapM#-}mapM :: (a -> m b) -> [a] -> m [b]mapMa -> m bf[a]as=(a -> m [b] -> m [b]) -> m [b] -> [a] -> m [b]forall a b. (a -> b -> b) -> b -> [a] -> bfoldra -> m [b] -> m [b]k([b] -> m [b]forall (m :: * -> *) a. Monad m => a -> m areturn[])[a]aswherek :: a -> m [b] -> m [b]kaam [b]r=do{bx<-a -> m bfaa;[b]xs<-m [b]r;[b] -> m [b]forall (m :: * -> *) a. Monad m => a -> m areturn(bxb -> [b] -> [b]forall a. a -> [a] -> [a]:[b]xs)}{-Note: [sequence and mapM]~~~~~~~~~~~~~~~~~~~~~~~~~Originally, we definedmapM f = sequence . map fThis relied on list fusion to produce efficient code for mapM, and led toexcessive allocation in cryptarithm2. Definingsequence = mapM idrelies only on inlining a tiny function (id) and beta reduction, which tends tobe a more reliable aspect of simplification. Indeed, this does not lead tosimilar problems in nofib.-}-- | Promote a function to a monad.liftM::(Monadm)=>(a1->r)->ma1->mrliftM :: (a1 -> r) -> m a1 -> m rliftMa1 -> rfm a1m1=do{a1x1<-m a1m1;r -> m rforall (m :: * -> *) a. Monad m => a -> m areturn(a1 -> rfa1x1)}-- | 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::(Monadm)=>(a1->a2->r)->ma1->ma2->mrliftM2 :: (a1 -> a2 -> r) -> m a1 -> m a2 -> m rliftM2a1 -> a2 -> rfm a1m1m a2m2=do{a1x1<-m a1m1;a2x2<-m a2m2;r -> m rforall (m :: * -> *) a. Monad m => a -> m areturn(a1 -> a2 -> rfa1x1a2x2)}-- 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::(Monadm)=>(a1->a2->a3->r)->ma1->ma2->ma3->mrliftM3 :: (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m rliftM3a1 -> a2 -> a3 -> rfm a1m1m a2m2m a3m3=do{a1x1<-m a1m1;a2x2<-m a2m2;a3x3<-m a3m3;r -> m rforall (m :: * -> *) a. Monad m => a -> m areturn(a1 -> a2 -> a3 -> rfa1x1a2x2a3x3)}-- | Promote a function to a monad, scanning the monadic arguments from-- left to right (cf. 'liftM2').liftM4::(Monadm)=>(a1->a2->a3->a4->r)->ma1->ma2->ma3->ma4->mrliftM4 :: (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m rliftM4a1 -> a2 -> a3 -> a4 -> rfm a1m1m a2m2m a3m3m a4m4=do{a1x1<-m a1m1;a2x2<-m a2m2;a3x3<-m a3m3;a4x4<-m a4m4;r -> m rforall (m :: * -> *) a. Monad m => a -> m areturn(a1 -> a2 -> a3 -> a4 -> rfa1x1a2x2a3x3a4x4)}-- | Promote a function to a monad, scanning the monadic arguments from-- left to right (cf. 'liftM2').liftM5::(Monadm)=>(a1->a2->a3->a4->a5->r)->ma1->ma2->ma3->ma4->ma5->mrliftM5 :: (a1 -> a2 -> a3 -> a4 -> a5 -> r)-> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m rliftM5a1 -> a2 -> a3 -> a4 -> a5 -> rfm a1m1m a2m2m a3m3m a4m4m a5m5=do{a1x1<-m a1m1;a2x2<-m a2m2;a3x3<-m a3m3;a4x4<-m a4m4;a5x5<-m a5m5;r -> m rforall (m :: * -> *) a. Monad m => a -> m areturn(a1 -> a2 -> a3 -> a4 -> a5 -> rfa1x1a2x2a3x3a4x4a5x5)}{-# INLINABLEliftM#-}{-# SPECIALISEliftM::(a1->r)->IOa1->IOr#-}{-# SPECIALISEliftM::(a1->r)->Maybea1->Mayber#-}{-# INLINABLEliftM2#-}{-# SPECIALISEliftM2::(a1->a2->r)->IOa1->IOa2->IOr#-}{-# SPECIALISEliftM2::(a1->a2->r)->Maybea1->Maybea2->Mayber#-}{-# INLINABLEliftM3#-}{-# SPECIALISEliftM3::(a1->a2->a3->r)->IOa1->IOa2->IOa3->IOr#-}{-# SPECIALISEliftM3::(a1->a2->a3->r)->Maybea1->Maybea2->Maybea3->Mayber#-}{-# INLINABLEliftM4#-}{-# SPECIALISEliftM4::(a1->a2->a3->a4->r)->IOa1->IOa2->IOa3->IOa4->IOr#-}{-# SPECIALISEliftM4::(a1->a2->a3->a4->r)->Maybea1->Maybea2->Maybea3->Maybea4->Mayber#-}{-# INLINABLEliftM5#-}{-# SPECIALISEliftM5::(a1->a2->a3->a4->a5->r)->IOa1->IOa2->IOa3->IOa4->IOa5->IOr#-}{-# SPECIALISEliftM5::(a1->a2->a3->a4->a5->r)->Maybea1->Maybea2->Maybea3->Maybea4->Maybea5->Mayber#-}{- | In many situations, the 'liftM' operations can be replaced by uses of'ap', which promotes function application.> return f `ap` x1 `ap` ... `ap` xnis equivalent to> liftMn f x1 x2 ... xn-}ap::(Monadm)=>m(a->b)->ma->mbap :: m (a -> b) -> m a -> m bapm (a -> b)m1m am2=do{a -> bx1<-m (a -> b)m1;ax2<-m am2;b -> m bforall (m :: * -> *) a. Monad m => a -> m areturn(a -> bx1ax2)}-- Since many Applicative instances define (<*>) = ap, we-- cannot define ap = (<*>){-# INLINABLEap#-}{-# SPECIALISEap::IO(a->b)->IOa->IOb#-}{-# SPECIALISEap::Maybe(a->b)->Maybea->Maybeb#-}-- instances for Prelude types-- | @since 2.01instanceFunctor((->)r)wherefmap :: (a -> b) -> (r -> a) -> r -> bfmap=(a -> b) -> (r -> a) -> r -> bforall b c a. (b -> c) -> (a -> b) -> a -> c(.)-- | @since 2.01instanceApplicative((->)r)wherepure :: a -> r -> apure=a -> r -> aforall a b. a -> b -> aconst<*> :: (r -> a -> b) -> (r -> a) -> r -> b(<*>)r -> a -> bfr -> agrx=r -> a -> bfrx(r -> agrx)liftA2 :: (a -> b -> c) -> (r -> a) -> (r -> b) -> r -> cliftA2a -> b -> cqr -> afr -> bgrx=a -> b -> cq(r -> afrx)(r -> bgrx)-- | @since 2.01instanceMonad((->)r)wherer -> af>>= :: (r -> a) -> (a -> r -> b) -> r -> b>>=a -> r -> bk=\rr->a -> r -> bk(r -> afrr)rr-- | @since 2.01instanceFunctor((,)a)wherefmap :: (a -> b) -> (a, a) -> (a, b)fmapa -> bf(ax,ay)=(ax,a -> bfay)-- | @since 2.01instanceFunctorMaybewherefmap :: (a -> b) -> Maybe a -> Maybe bfmapa -> b_Maybe aNothing=Maybe bforall a. Maybe aNothingfmapa -> bf(Justaa)=b -> Maybe bforall a. a -> Maybe aJust(a -> bfaa)-- | @since 2.01instanceApplicativeMaybewherepure :: a -> Maybe apure=a -> Maybe aforall a. a -> Maybe aJustJusta -> bf<*> :: Maybe (a -> b) -> Maybe a -> Maybe b<*>Maybe am=(a -> b) -> Maybe a -> Maybe bforall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f bfmapa -> bfMaybe amMaybe (a -> b)Nothing<*>Maybe a_m=Maybe bforall a. Maybe aNothingliftA2 :: (a -> b -> c) -> Maybe a -> Maybe b -> Maybe cliftA2a -> b -> cf(Justax)(Justby)=c -> Maybe cforall a. a -> Maybe aJust(a -> b -> cfaxby)liftA2a -> b -> c_Maybe a_Maybe b_=Maybe cforall a. Maybe aNothingJusta_m1*> :: Maybe a -> Maybe b -> Maybe b*>Maybe bm2=Maybe bm2Maybe aNothing*>Maybe b_m2=Maybe bforall a. Maybe aNothing-- | @since 2.01instanceMonadMaybewhere(Justax)>>= :: Maybe a -> (a -> Maybe b) -> Maybe b>>=a -> Maybe bk=a -> Maybe bkaxMaybe aNothing>>=a -> Maybe b_=Maybe bforall a. Maybe aNothing>> :: Maybe a -> Maybe b -> Maybe b(>>)=Maybe a -> Maybe b -> Maybe bforall (f :: * -> *) a b. Applicative f => f a -> f b -> f b(*>)-- ------------------------------------------------------------------------------- The Alternative class definitioninfixl3<|>-- | A monoid on applicative functors.---- If defined, 'some' and 'many' should be the least solutions-- of the equations:---- * @'some' v = (:) 'Prelude.<$>' v '<*>' 'many' v@---- * @'many' v = 'some' v '<|>' 'pure' []@classApplicativef=>Alternativefwhere-- | The identity of '<|>'empty::fa-- | An associative binary operation(<|>)::fa->fa->fa-- | One or more.some::fa->f[a]somef av=f [a]some_vwheremany_v :: f [a]many_v=f [a]some_vf [a] -> f [a] -> f [a]forall (f :: * -> *) a. Alternative f => f a -> f a -> f a<|>[a] -> f [a]forall (f :: * -> *) a. Applicative f => a -> f apure[]some_v :: f [a]some_v=(a -> [a] -> [a]) -> f a -> f [a] -> f [a]forall (f :: * -> *) a b c.Applicative f =>(a -> b -> c) -> f a -> f b -> f cliftA2(:)f avf [a]many_v-- | Zero or more.many::fa->f[a]manyf av=f [a]many_vwheremany_v :: f [a]many_v=f [a]some_vf [a] -> f [a] -> f [a]forall (f :: * -> *) a. Alternative f => f a -> f a -> f a<|>[a] -> f [a]forall (f :: * -> *) a. Applicative f => a -> f apure[]some_v :: f [a]some_v=(a -> [a] -> [a]) -> f a -> f [a] -> f [a]forall (f :: * -> *) a b c.Applicative f =>(a -> b -> c) -> f a -> f b -> f cliftA2(:)f avf [a]many_v-- | @since 2.01instanceAlternativeMaybewhereempty :: Maybe aempty=Maybe aforall a. Maybe aNothingMaybe aNothing<|> :: Maybe a -> Maybe a -> Maybe a<|>Maybe ar=Maybe arMaybe al<|>Maybe a_=Maybe al-- ------------------------------------------------------------------------------- The MonadPlus class definition-- | Monads that also support choice and failure.class(Alternativem,Monadm)=>MonadPlusmwhere-- | The identity of 'mplus'.  It should also satisfy the equations---- > mzero >>= f  =  mzero-- > v >> mzero   =  mzero---- The default definition is---- @-- mzero = 'empty'-- @mzero::mamzero=m aforall (f :: * -> *) a. Alternative f => f aempty-- | An associative operation. The default definition is---- @-- mplus = ('<|>')-- @mplus::ma->ma->mamplus=m a -> m a -> m aforall (f :: * -> *) a. Alternative f => f a -> f a -> f a(<|>)-- | @since 2.01instanceMonadPlusMaybe----------------------------------------------- The non-empty list typeinfixr5:|-- | Non-empty (and non-strict) list type.---- @since 4.9.0.0dataNonEmptya=a:|[a]deriving(Eq-- ^ @since 4.9.0.0,Ord-- ^ @since 4.9.0.0)-- | @since 4.9.0.0instanceFunctorNonEmptywherefmap :: (a -> b) -> NonEmpty a -> NonEmpty bfmapa -> bf~(aa:|[a]as)=a -> bfaab -> [b] -> NonEmpty bforall a. a -> [a] -> NonEmpty a:|(a -> b) -> [a] -> [b]forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f bfmapa -> bf[a]asab<$ :: a -> NonEmpty b -> NonEmpty a<$~(b_:|[b]as)=aba -> [a] -> NonEmpty aforall a. a -> [a] -> NonEmpty a:|(aba -> [b] -> [a]forall (f :: * -> *) a b. Functor f => a -> f b -> f a<$[b]as)-- | @since 4.9.0.0instanceApplicativeNonEmptywherepure :: a -> NonEmpty apureaa=aaa -> [a] -> NonEmpty aforall a. a -> [a] -> NonEmpty a:|[]<*> :: NonEmpty (a -> b) -> NonEmpty a -> NonEmpty b(<*>)=NonEmpty (a -> b) -> NonEmpty a -> NonEmpty bforall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m bapliftA2 :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty cliftA2=(a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty cforall (m :: * -> *) a1 a2 r.Monad m =>(a1 -> a2 -> r) -> m a1 -> m a2 -> m rliftM2-- | @since 4.9.0.0instanceMonadNonEmptywhere~(aa:|[a]as)>>= :: NonEmpty a -> (a -> NonEmpty b) -> NonEmpty b>>=a -> NonEmpty bf=bbb -> [b] -> NonEmpty bforall a. a -> [a] -> NonEmpty a:|([b]bs[b] -> [b] -> [b]forall a. [a] -> [a] -> [a]++[b]bs')wherebb:|[b]bs=a -> NonEmpty bfaabs' :: [b]bs'=[a]as[a] -> (a -> [b]) -> [b]forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b>>=NonEmpty b -> [b]forall a. NonEmpty a -> [a]toList(NonEmpty b -> [b]) -> (a -> NonEmpty b) -> a -> [b]forall b c a. (b -> c) -> (a -> b) -> a -> c.a -> NonEmpty bftoList :: NonEmpty a -> [a]toList~(ac:|[a]cs)=aca -> [a] -> [a]forall a. a -> [a] -> [a]:[a]cs------------------------------------------------ The list type-- | @since 2.01instanceFunctor[]where{-# INLINEfmap#-}fmap :: (a -> b) -> [a] -> [b]fmap=(a -> b) -> [a] -> [b]forall a b. (a -> b) -> [a] -> [b]map-- See Note: [List comprehensions and inlining]-- | @since 2.01instanceApplicative[]where{-# INLINEpure#-}pure :: a -> [a]pureax=[ax]{-# INLINE(<*>)#-}[a -> b]fs<*> :: [a -> b] -> [a] -> [b]<*>[a]xs=[a -> bfax|a -> bf<-[a -> b]fs,ax<-[a]xs]{-# INLINEliftA2#-}liftA2 :: (a -> b -> c) -> [a] -> [b] -> [c]liftA2a -> b -> cf[a]xs[b]ys=[a -> b -> cfaxby|ax<-[a]xs,by<-[b]ys]{-# INLINE(*>)#-}[a]xs*> :: [a] -> [b] -> [b]*>[b]ys=[by|a_<-[a]xs,by<-[b]ys]-- See Note: [List comprehensions and inlining]-- | @since 2.01instanceMonad[]where{-# INLINE(>>=)#-}[a]xs>>= :: [a] -> (a -> [b]) -> [b]>>=a -> [b]f=[by|ax<-[a]xs,by<-a -> [b]fax]{-# INLINE(>>)#-}>> :: [a] -> [b] -> [b](>>)=[a] -> [b] -> [b]forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b(*>)-- | @since 2.01instanceAlternative[]whereempty :: [a]empty=[]<|> :: [a] -> [a] -> [a](<|>)=[a] -> [a] -> [a]forall a. [a] -> [a] -> [a](++)-- | @since 2.01instanceMonadPlus[]{-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 :: (a -> b -> b) -> b -> [a] -> bfoldra -> b -> bkbz=[a] -> bgowherego :: [a] -> bgo[]=bzgo(ay:[a]ys)=aya -> b -> b`k`[a] -> bgo[a]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::foralla.(forallb.(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 1build :: (forall b. (a -> b -> b) -> b -> b) -> [a]buildforall b. (a -> b -> b) -> b -> bg=(a -> [a] -> [a]) -> [a] -> [a]forall b. (a -> b -> b) -> b -> bg(:)[]-- | 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::foralla.(forallb.(a->b->b)->b->b)->[a]->[a]{-# INLINE[1]augment#-}augment :: (forall b. (a -> b -> b) -> b -> b) -> [a] -> [a]augmentforall b. (a -> b -> b) -> b -> bg[a]xs=(a -> [a] -> [a]) -> [a] -> [a]forall b. (a -> b -> b) -> b -> bg(:)[a]xs{-# RULES"fold/build"forallkz(g::forallb.(a->b->b)->b->b).foldrkz(buildg)=gkz"foldr/augment"forallkzxs(g::forallb.(a->b->b)->b->b).foldrkz(augmentgxs)=gk(foldrkzxs)"foldr/id"foldr(:)[]=\x->x"foldr/app"[1]forallys.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"forallkzx.foldrkz[x]=kxz"foldr/nil"forallkz.foldrkz[]=z"foldr/cons/build"forallkzx(g::forallb.(a->b->b)->b->b).foldrkz(x:buildg)=kx(gkz)"augment/build"forall(g::forallb.(a->b->b)->b->b)(h::forallb.(a->b->b)->b->b).augmentg(buildh)=build(\cn->gc(hcn))"augment/nil"forall(g::forallb.(a->b->b)->b->b).augmentg[]=buildg#-}-- This rule is true, but not (I think) useful:--      augment g (augment h t) = augment (\cn -> g c (h c n)) t------------------------------------------------              map------------------------------------------------ | \(\mathcal{O}(n)\). '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 (+1) [1, 2, 3]--- [2,3,4]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 warningsmap :: (a -> b) -> [a] -> [b]mapa -> b_[]=[]mapa -> bf(ax:[a]xs)=a -> bfaxb -> [b] -> [b]forall a. a -> [a] -> [a]:(a -> b) -> [a] -> [b]forall a b. (a -> b) -> [a] -> [b]mapa -> bf[a]xs-- Note eta expandedmapFB::(elt->lst->lst)->(a->elt)->a->lst->lst{-# INLINE[0]mapFB#-}-- See Note [Inline FB functions] in GHC.ListmapFB :: (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lstmapFBelt -> lst -> lstca -> eltf=\axlstys->elt -> lst -> lstc(a -> eltfax)lstys{- 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]forallfxs.mapfxs=build(\cn->foldr(mapFBcf)nxs)"mapList"[1]forallf.foldr(mapFB(:)f)[]=mapf"mapFB"forallcfg.mapFB(mapFBcf)g=mapFBc(f.g)"mapFB/id"forallc.mapFBc(\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]mapcoerce=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++ :: [a] -> [a] -> [a](++)[][a]ys=[a]ys(++)(ax:[a]xs)[a]ys=axa -> [a] -> [a]forall a. a -> [a] -> [a]:[a]xs[a] -> [a] -> [a]forall a. [a] -> [a] -> [a]++[a]ys{-# RULES"++"[~1]forallxsys.xs++ys=augment(\cn->foldrcnxs)ys#-}-- |'otherwise' is defined as the value 'True'.  It helps to make-- guards more readable.  eg.---- >  f x | x < 0     = ...-- >      | otherwise = ...otherwise::Boolotherwise :: Boolotherwise=BoolTrue------------------------------------------------ Type Char and String------------------------------------------------ | A 'String' is a list of characters.  String constants in Haskell are values-- of type 'String'.---- See "Data.List" for operations on lists.typeString=[Char]unsafeChr::Int->CharunsafeChr :: Int -> CharunsafeChr(I#Int#i#)=Char# -> CharC#(Int# -> Char#chr#Int#i#)-- | The 'Prelude.fromEnum' method restricted to the type 'Data.Char.Char'.ord::Char->Intord :: Char -> Intord(C#Char#c#)=Int# -> IntI#(Char# -> Int#ord#Char#c#)-- | This 'String' equality predicate is used when desugaring-- pattern-matches against strings.eqString::String->String->BooleqString :: String -> String -> BooleqString[][]=BoolTrueeqString(Charc1:Stringcs1)(Charc2:Stringcs2)=Charc1Char -> Char -> Boolforall a. Eq a => a -> a -> Bool==Charc2Bool -> Bool -> Bool&&Stringcs1String -> String -> Bool`eqString`Stringcs2eqStringString_String_=BoolFalse{-# 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 == 31minInt=I#(-0x40000000#)maxInt=I#0x3FFFFFFF##elif WORD_SIZE_IN_BITS == 32minInt=I#(-0x80000000#)maxInt=I#0x7FFFFFFF##elseminInt :: IntminInt=Int# -> IntI#(Int#-0x8000000000000000#)maxInt :: IntmaxInt=Int# -> IntI#Int#0x7FFFFFFFFFFFFFFF##endif------------------------------------------------ The function type------------------------------------------------ | Identity function.---- > id x = xid::a->aid :: a -> aidax=ax-- 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 'Control.Exception.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.hsassert::Bool->a->aassert :: Bool -> a -> aassertBool_predar=arbreakpoint::a->abreakpoint :: a -> abreakpointar=arbreakpointCond::Bool->a->abreakpointCond :: Bool -> a -> abreakpointCondBool_ar=ardataOpaque=foralla.Oa-- | @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->aconst :: a -> b -> aconstaxb_=ax-- | 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. :: (b -> c) -> (a -> b) -> a -> c(.)b -> cfa -> bg=\ax->b -> cf(a -> bgax)-- | @'flip' f@ takes its (first) two arguments in the reverse order of @f@.---- >>> flip (++) "hello" "world"-- "worldhello"flip::(a->b->c)->b->a->cflip :: (a -> b -> c) -> b -> a -> cflipa -> b -> cfbxay=a -> b -> cfaybx-- | 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@.---- Note that @('$')@ is levity-polymorphic in its result type, so that-- @foo '$' True@ where @foo :: Bool -> Int#@ is well-typed.{-# INLINE($)#-}($)::forallra(b::TYPEr).(a->b)->a->ba -> bf$ :: (a -> b) -> a -> b$ax=a -> bfax-- | 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.($!)::forallra(b::TYPEr).(a->b)->a->ba -> bf$! :: (a -> b) -> a -> b$!ax=let!vx :: avx=axina -> bfavx-- see #2273-- | @'until' p f@ yields the result of applying @f@ until @p@ holds.until::(a->Bool)->(a->a)->a->auntil :: (a -> Bool) -> (a -> a) -> a -> auntila -> Boolpa -> af=a -> agowherego :: a -> agoax|a -> Boolpax=ax|Boolotherwise=a -> ago(a -> afax)-- | '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->aasTypeOf :: a -> a -> aasTypeOf=a -> a -> aforall a b. a -> b -> aconst------------------------------------------------ Functor/Applicative/Monad instances for IO------------------------------------------------ | @since 2.01instanceFunctorIOwherefmap :: (a -> b) -> IO a -> IO bfmapa -> bfIO ax=IO axIO a -> (a -> IO b) -> IO bforall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b>>=(b -> IO bforall (f :: * -> *) a. Applicative f => a -> f apure(b -> IO b) -> (a -> b) -> a -> IO bforall b c a. (b -> c) -> (a -> b) -> a -> c.a -> bf)-- | @since 2.01instanceApplicativeIOwhere{-# INLINEpure#-}{-# INLINE(*>)#-}{-# INLINEliftA2#-}pure :: a -> IO apure=a -> IO aforall a. a -> IO areturnIO*> :: IO a -> IO b -> IO b(*>)=IO a -> IO b -> IO bforall a b. IO a -> IO b -> IO bthenIO<*> :: IO (a -> b) -> IO a -> IO b(<*>)=IO (a -> b) -> IO a -> IO bforall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m bapliftA2 :: (a -> b -> c) -> IO a -> IO b -> IO cliftA2=(a -> b -> c) -> IO a -> IO b -> IO cforall (m :: * -> *) a1 a2 r.Monad m =>(a1 -> a2 -> r) -> m a1 -> m a2 -> m rliftM2-- | @since 2.01instanceMonadIOwhere{-# INLINE(>>)#-}{-# INLINE(>>=)#-}>> :: IO a -> IO b -> IO b(>>)=IO a -> IO b -> IO bforall (f :: * -> *) a b. Applicative f => f a -> f b -> f b(*>)>>= :: IO a -> (a -> IO b) -> IO b(>>=)=IO a -> (a -> IO b) -> IO bforall a b. IO a -> (a -> IO b) -> IO bbindIO-- | @since 4.9.0.0instanceAlternativeIOwhereempty :: IO aempty=String -> IO aforall a. String -> IO afailIOString"mzero"<|> :: IO a -> IO a -> IO a(<|>)=IO a -> IO a -> IO aforall a. IO a -> IO a -> IO amplusIO-- | @since 4.9.0.0instanceMonadPlusIOreturnIO::a->IOareturnIO :: a -> IO areturnIOax=(State# RealWorld -> (# State# RealWorld, a #)) -> IO aforall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO aIO(\State# RealWorlds->(#State# RealWorlds,ax#))bindIO::IOa->(a->IOb)->IObbindIO :: IO a -> (a -> IO b) -> IO bbindIO(IOState# RealWorld -> (# State# RealWorld, a #)m)a -> IO bk=(State# RealWorld -> (# State# RealWorld, b #)) -> IO bforall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO aIO(\State# RealWorlds->caseState# RealWorld -> (# State# RealWorld, a #)mState# RealWorldsof(#State# RealWorldnew_s,aa#)->IO b -> State# RealWorld -> (# State# RealWorld, b #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(a -> IO bkaa)State# RealWorldnew_s)thenIO::IOa->IOb->IObthenIO :: IO a -> IO b -> IO bthenIO(IOState# RealWorld -> (# State# RealWorld, a #)m)IO bk=(State# RealWorld -> (# State# RealWorld, b #)) -> IO bforall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO aIO(\State# RealWorlds->caseState# RealWorld -> (# State# RealWorld, a #)mState# RealWorldsof(#State# RealWorldnew_s,a_#)->IO b -> State# RealWorld -> (# State# RealWorld, b #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIOIO bkState# RealWorldnew_s)-- Note that it is import that we do not SOURCE import this as-- its demand signature encodes knowledge of its bottoming-- behavior, which can expose useful simplifications. See-- #16588.failIO::String->IOafailIO :: String -> IO afailIOStrings=(State# RealWorld -> (# State# RealWorld, a #)) -> IO aforall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO aIO(SomeException -> State# RealWorld -> (# State# RealWorld, a #)forall a b. a -> State# RealWorld -> (# State# RealWorld, b #)raiseIO#(String -> SomeExceptionmkUserErrorStrings))unIO::IOa->(State#RealWorld->(#State#RealWorld,a#))unIO :: IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(IOState# RealWorld -> (# State# RealWorld, a #)a)=State# RealWorld -> (# State# RealWorld, a #)a{- |Returns the tag of a constructor application; this function is usedby the deriving code for Eq, Ord and Enum.-}{-# INLINEgetTag#-}getTag::a->Int#getTag :: a -> Int#getTagax=a -> Int#forall a. a -> Int#dataToTag#ax------------------------------------------------ Numeric primops------------------------------------------------ Definitions of the boxed PrimOps; these will be-- used in the case of partial applications, etc.{-# INLINEquotInt#-}{-# INLINEremInt#-}quotInt,remInt,divInt,modInt::Int->Int->Int(I#Int#x)quotInt :: Int -> Int -> Int`quotInt`(I#Int#y)=Int# -> IntI#(Int#xInt# -> Int# -> Int#`quotInt#`Int#y)(I#Int#x)remInt :: Int -> Int -> Int`remInt`(I#Int#y)=Int# -> IntI#(Int#xInt# -> Int# -> Int#`remInt#`Int#y)(I#Int#x)divInt :: Int -> Int -> Int`divInt`(I#Int#y)=Int# -> IntI#(Int#xInt# -> Int# -> Int#`divInt#`Int#y)(I#Int#x)modInt :: Int -> Int -> Int`modInt`(I#Int#y)=Int# -> IntI#(Int#xInt# -> Int# -> Int#`modInt#`Int#y)quotRemInt::Int->Int->(Int,Int)(I#Int#x)quotRemInt :: Int -> Int -> (Int, Int)`quotRemInt`(I#Int#y)=caseInt#xInt# -> Int# -> (# Int#, Int# #)`quotRemInt#`Int#yof(#Int#q,Int#r#)->(Int# -> IntI#Int#q,Int# -> IntI#Int#r)divModInt::Int->Int->(Int,Int)(I#Int#x)divModInt :: Int -> Int -> (Int, Int)`divModInt`(I#Int#y)=caseInt#xInt# -> Int# -> (# Int#, Int# #)`divModInt#`Int#yof(#Int#q,Int#r#)->(Int# -> IntI#Int#q,Int# -> IntI#Int#r)divModInt#::Int#->Int#->(#Int#,Int##)Int#x#divModInt# :: Int# -> Int# -> (# Int#, Int# #)`divModInt#`Int#y#|Int# -> BoolisTrue#(Int#x#Int# -> Int# -> Int#>#Int#0#)Bool -> Bool -> Bool&&Int# -> BoolisTrue#(Int#y#Int# -> Int# -> Int#<#Int#0#)=case(Int#x#Int# -> Int# -> Int#-#Int#1#)Int# -> Int# -> (# Int#, Int# #)`quotRemInt#`Int#y#of(#Int#q,Int#r#)->(#Int#qInt# -> Int# -> Int#-#Int#1#,Int#rInt# -> Int# -> Int#+#Int#y#Int# -> Int# -> Int#+#Int#1##)|Int# -> BoolisTrue#(Int#x#Int# -> Int# -> Int#<#Int#0#)Bool -> Bool -> Bool&&Int# -> BoolisTrue#(Int#y#Int# -> Int# -> Int#>#Int#0#)=case(Int#x#Int# -> Int# -> Int#+#Int#1#)Int# -> Int# -> (# Int#, Int# #)`quotRemInt#`Int#y#of(#Int#q,Int#r#)->(#Int#qInt# -> Int# -> Int#-#Int#1#,Int#rInt# -> Int# -> Int#+#Int#y#Int# -> Int# -> Int#-#Int#1##)|Boolotherwise=Int#x#Int# -> Int# -> (# Int#, Int# #)`quotRemInt#`Int#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#Word#ashiftL# :: Word# -> Int# -> Word#`shiftL#`Int#b|Int# -> BoolisTrue#(Int#bInt# -> Int# -> Int#>=#WORD_SIZE_IN_BITS#)=0##|Boolotherwise=Word#aWord# -> Int# -> Word#`uncheckedShiftL#`Int#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#Word#ashiftRL# :: Word# -> Int# -> Word#`shiftRL#`Int#b|Int# -> BoolisTrue#(Int#bInt# -> Int# -> Int#>=#WORD_SIZE_IN_BITS#)=0##|Boolotherwise=Word#aWord# -> Int# -> Word#`uncheckedShiftRL#`Int#b-- | Shift the argument left by the specified number of bits-- (which must be non-negative).iShiftL#::Int#->Int#->Int#Int#aiShiftL# :: Int# -> Int# -> Int#`iShiftL#`Int#b|Int# -> BoolisTrue#(Int#bInt# -> Int# -> Int#>=#WORD_SIZE_IN_BITS#)=0#|Boolotherwise=Int#aInt# -> Int# -> Int#`uncheckedIShiftL#`Int#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#Int#aiShiftRA# :: Int# -> Int# -> Int#`iShiftRA#`Int#b|Int# -> BoolisTrue#(Int#bInt# -> Int# -> Int#>=#WORD_SIZE_IN_BITS#)=ifisTrue#(a<#0#)then(-1#)else0#|Boolotherwise=Int#aInt# -> Int# -> Int#`uncheckedIShiftRA#`Int#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#Int#aiShiftRL# :: Int# -> Int# -> Int#`iShiftRL#`Int#b|Int# -> BoolisTrue#(Int#bInt# -> Int# -> Int#>=#WORD_SIZE_IN_BITS#)=0#|Boolotherwise=Int#aInt# -> Int# -> Int#`uncheckedIShiftRL#`Int#b-- Rules for C strings (the functions themselves are now in GHC.CString){-# RULES"unpack"[~1]foralla.unpackCString#a=build(unpackFoldrCString#a)"unpack-list"[1]foralla.unpackFoldrCString#a(:)[]=unpackCString#a"unpack-append"forallan.unpackFoldrCString#a(:)n=unpackAppendCString#an-- There's a built-in rule (in PrelRules.hs) for--      unpackFoldr "foo" c (unpackFoldr "baz" c n)  =  unpackFoldr "foobaz" c n#-}

[8]ページ先頭

©2009-2025 Movatter.jp