HORIZON HASKELLDocslts/ghc-10.0.xaa25b892026-10-10Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · aa25b89 · 2026-10-10

Moduleghc-internal-10.0.0Haskell2010

GHC.Internal.Base

Basic data types and classes.

  • 4 types
  • 7 classes
  • 59 values
Example1 expression
import GHC.Internal.Num
datadata Void
#

Uninhabited data type

Instances11Eq, Data, Ord, Read, Show, Ix, …
  • Eq VoidDefined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Data VoidDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Data
  • Ord VoidDefined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Read VoidDefined in ghc-internal-10.0.0 · GHC.Internal.Read

    Reading a Void value is always a parse error, considering Void as a data type with no constructors.

  • Show VoidDefined in ghc-internal-10.0.0 · GHC.Internal.Show
  • Ix VoidDefined in ghc-internal-10.0.0 · GHC.Internal.Ix
  • Generic VoidDefined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Semigroup VoidDefined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Exception VoidDefined in ghc-internal-10.0.0 · GHC.Internal.Exception.Type
  • Lift VoidDefined in ghc-internal-10.0.0 · GHC.Internal.TH.Lift
  • type Rep Void = D1 ('MetaData "Void" "GHC.Internal.Base" "ghc-internal" 'False) V1Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
valueabsurd :: Void -> a
#

Since Void values logically don't exist, this witnesses the logical reasoning tool of "ex falso quodlibet".

Example2 expressions
let x :: Either Void Int; x = Right 5:{case x of    Right r -> r    Left l  -> absurd l:}5
valuevacuous :: Functor f => f Void -> f a
#

If Void is uninhabited then any Functor that holds only values of type Void is holding no values. It is implemented in terms of fmap absurd.

classclass Semigroup a where
#

The class of semigroups (types with an associative binary operation).

Instances should satisfy the following:

Associativity

x <> (y <> z) = (x <> y) <> z

You can alternatively define sconcat instead of (<>), in which case the laws are:

Unit

sconcat (pure x) = x

Multiplication

sconcat (join xss) = sconcat (fmap sconcat xss)

Methods

  • (<>) :: a -> a -> ainfixr 6

    An associative operation.

    Examples
    Example1 expression
    [1,2,3] <> [4,5,6][1,2,3,4,5,6]
    Example1 expression
    Just [1, 2, 3] <> Just [4, 5, 6]Just [1,2,3,4,5,6]
    Example1 expression
    putStr "Hello, " <> putStrLn "World!"Hello, World!
  • sconcat :: NonEmpty a -> a

    Reduce a non-empty list with <>

    The default definition should be sufficient, but this can be overridden for efficiency.

    Examples

    For the following examples, we will assume that we have:

    Example1 expression
    import Data.List.NonEmpty (NonEmpty (..))
    Example1 expression
    sconcat $ "Hello" :| [" ", "Haskell", "!"]"Hello Haskell!"
    Example1 expression
    sconcat $ Just [1, 2, 3] :| [Nothing, Just [4, 5, 6]]Just [1,2,3,4,5,6]
    Example1 expression
    sconcat $ Left 1 :| [Right 2, Left 3, Right 4]Right 2
  • stimes :: Integral b => b -> a -> a

    Repeat a value n times.

    The default definition will raise an exception for a multiplier that is <= 0. This may be overridden with an implementation that is total. For monoids it is preferred to use stimesMonoid.

    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 = Data.Semigroup.stimesIdempotentMonoid respectively.

    Examples
    Example1 expression
    stimes 4 [1][1,1,1,1]
    Example1 expression
    stimes 5 (putStr "hi!")hi!hi!hi!hi!hi!
    Example1 expression
    stimes 3 (Right ":)")Right ":)"
Instances51Semigroup, …
classclass Semigroup a => Monoid a where
#

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

You can alternatively define mconcat instead of mempty, in which case the laws are:

Unit

mconcat (pure x) = x

Multiplication

mconcat (join xss) = mconcat (fmap mconcat xss)

Subclass

mconcat (toList xs) = sconcat xs

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 newtypes 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.

Methods

  • mempty :: a

    Identity of mappend

    Examples
    Example1 expression
    "Hello world" <> mempty"Hello world"
    Example1 expression
    mempty <> [1, 2, 3][1,2,3]
  • mappend :: a -> a -> 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.

  • mconcat :: [a] -> a

    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.

    Example1 expression
    mconcat ["Hello", " ", "Haskell", "!"]"Hello Haskell!"
Instances47Monoid, …
  • Monoid AllDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid AnyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid EventDefined in ghc-internal-10.0.0 · GHC.Internal.Event.Internal.Types
  • Monoid EventLifetimeDefined in ghc-internal-10.0.0 · GHC.Internal.Event.Internal.Types
  • Monoid LifetimeDefined in ghc-internal-10.0.0 · GHC.Internal.Event.Internal.Types

    mappend takes the longer of two lifetimes.

  • Monoid ExceptionContextDefined in ghc-internal-10.0.0 · GHC.Internal.Exception.Context
  • Monoid OrderingDefined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monoid ()Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monoid (First a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Monoid
  • Monoid (Last a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Monoid
  • Monoid (Endo a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid [a]Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monoid a => Monoid (Identity a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Identity
  • Monoid a => Monoid (Down a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Ord
  • Monoid a => Monoid (Dual a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid a => Monoid (STM a)Defined in ghc-internal-10.0.0 · GHC.Internal.STM
  • Monoid a => Monoid (Q a)Defined in ghc-internal-10.0.0 · GHC.Internal.TH.Monad
  • Monoid a => Monoid (IO a)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monoid a => Monoid (a)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monoid p => Monoid (Par1 p)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Semigroup a => Monoid (Maybe a)Defined in ghc-internal-10.0.0 · GHC.Internal.Base

    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.

  • Bits a => Monoid (Ior a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Bits
  • Bits a => Monoid (Xor a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Bits
  • FiniteBits a => Monoid (And a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Bits

    This constraint is arguably too strong. However, as some types (such as Natural) have undefined complement, this is the only safe choice.

  • FiniteBits a => Monoid (Iff a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Bits

    This constraint is arguably too strong. However, as some types (such as Natural) have undefined complement, this is the only safe choice.

  • Ord a => Monoid (Max a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Utils
  • Ord a => Monoid (Min a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Utils
  • Num a => Monoid (Product a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Num a => Monoid (Sum a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • (Generic a, Monoid (Rep a ())) => Monoid (Generically a)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Monoid (Proxy s)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Monoid (U1 p)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Monoid a => Monoid (ST s a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Monad.ST.Lazy.Imp
  • Monoid a => Monoid (ST s a)Defined in ghc-internal-10.0.0 · GHC.Internal.ST
  • Monoid b => Monoid (a -> b)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • (Monoid a, Monoid b) => Monoid (a, b)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Alternative f => Monoid (Alt f a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid (f p) => Monoid (Rec1 f p)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Monoid a => Monoid (Const a b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Const
  • (Applicative f, Monoid a) => Monoid (Ap f a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Monoid
  • (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monoid c => Monoid (K1 i c p)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • (Monoid (f p), Monoid (g p)) => Monoid ((:*:) f g p)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monoid (f (g p)) => Monoid ((:.:) f g p)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Monoid (f p) => Monoid (M1 i c f p)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
classclass Functor (f :: Type -> Type) where
#

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 the structure 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 and the first law, so you need only check that the former condition holds. See these articles by School of Haskell or David Luposchainsky for an explanation.

Methods

  • fmap :: (a -> b) -> f a -> f b

    fmap is used to apply a function of type (a -> b) to a value of type f a, where f is a functor, to produce a value of type f b. Note that for any type constructor with more than one parameter (e.g., Either), only the last type parameter can be modified with fmap (e.g., b in Either a b).

    Some type constructors with two parameters or more have a Data.Bifunctor.Bifunctor instance that allows both the last and the penultimate parameters to be mapped over.

    Examples

    Convert from a Data.Maybe.Maybe Int to a Maybe String using Prelude.show:

    Example2 expressions
    fmap show NothingNothingfmap show (Just 3)Just "3"

    Convert from an Data.Either.Either Int Int to an Either Int String using Prelude.show:

    Example2 expressions
    fmap show (Left 17)Left 17fmap show (Right 17)Right "17"

    Double each element of a list:

    Example1 expression
    fmap (*2) [1,2,3][2,4,6]

    Apply Prelude.even to the second element of a pair:

    Example1 expression
    fmap even (2,2)(2,True)

    It may seem surprising that the function is only applied to the last element of the tuple compared to the list example above which applies it to every element in the list. To understand, remember that tuples are type constructors with multiple type parameters: a tuple of 3 elements (a,b,c) can also be written (,,) a b c and its Functor instance is defined for Functor ((,,) a b) (i.e., only the third parameter is free to be mapped over with fmap).

    It explains why fmap can be used with tuples containing values of different types as in the following example:

    Example1 expression
    fmap even ("hello", 1.0, 4)("hello",1.0,True)
  • (<$) :: a -> f b -> f ainfixl 4

    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.

    Examples

    Perform a computation with Maybe and replace the result with a constant value if it is Just:

    Example2 expressions
    'a' <$ Just 2Just 'a''a' <$ NothingNothing
Instances61Functor, …
  • Functor NonEmptyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.NonEmpty · orphan
  • Functor HandlerDefined in ghc-internal-10.0.0 · GHC.Internal.Control.Exception
  • Functor IdentityDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Identity
  • Functor FirstDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Monoid
  • Functor LastDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Monoid
  • Functor DownDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Ord
  • Functor DualDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Functor ProductDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Functor SumDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Functor ZipListDefined in ghc-internal-10.0.0 · GHC.Internal.Functor.ZipList
  • Functor NoIODefined in ghc-internal-10.0.0 · GHC.Internal.GHCi
  • Functor Par1Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor GenClosureDefined in ghc-internal-10.0.0 · GHC.Internal.Heap.Closures
  • Functor GenStackFieldDefined in ghc-internal-10.0.0 · GHC.Internal.Heap.Closures
  • Functor GenStackFrameDefined in ghc-internal-10.0.0 · GHC.Internal.Heap.Closures
  • Functor GenStgStackClosureDefined in ghc-internal-10.0.0 · GHC.Internal.Heap.Closures
  • Functor MaybeDefined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Functor STMDefined in ghc-internal-10.0.0 · GHC.Internal.STM
  • Functor QDefined in ghc-internal-10.0.0 · GHC.Internal.TH.Monad
  • Functor TyVarBndrDefined in ghc-internal-10.0.0 · GHC.Internal.TH.Syntax
  • Functor PDefined in ghc-internal-10.0.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • Functor ReadPDefined in ghc-internal-10.0.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • Functor ReadPrecDefined in ghc-internal-10.0.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • Functor SoloDefined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Functor IODefined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Functor []Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Functor ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Functor U1Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor V1Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (Array i)Defined in ghc-internal-10.0.0 · GHC.Internal.Arr
  • Functor (ST s)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Monad.ST.Lazy.Imp
  • Functor (Either a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Either
  • Functor (StateL s)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Utils
  • Functor (StateR s)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Utils
  • Functor (ST s)Defined in ghc-internal-10.0.0 · GHC.Internal.ST
  • Functor (Tuple2 a)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Arrow a => Functor (ArrowMonad a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
  • Functor (Const m)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Const
  • Functor (URec Char)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (URec Double)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (URec Float)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (URec Int)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (URec Word)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (URec (Ptr ()))Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (Tuple3 a b)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Functor f => Functor (Ap f)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Monoid
  • Functor f => Functor (Alt f)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Functor f => Functor (Rec1 f)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor m => Functor (Kleisli m a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
  • Monad m => Functor (StateT s m)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Utils
  • (Generic1 f, Functor (Rep1 f)) => Functor (Generically1 f)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (K1 i c)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (Tuple4 a b c)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Functor ((->) r)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • (Functor f, Functor g) => Functor (f :*: g)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • (Functor f, Functor g) => Functor (f :+: g)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (Tuple5 a b c d)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Functor f => Functor (M1 i c f)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • (Functor f, Functor g) => Functor (f :.: g)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Functor (Tuple6 a b c d e)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Functor (Tuple7 a b c d e f)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
classclass Functor f => Applicative (f :: Type -> Type) where
#

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 one 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:

As a consequence of these laws, the Functor instance for f will satisfy

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

(which implies that pure and <*> satisfy the applicative functor laws).

Methods

  • pure :: a -> f a

    Lift a value into the Structure.

    Examples
    Example1 expression
    pure 1 :: Maybe IntJust 1
    Example1 expression
    pure 'z' :: [Char]"z"
    Example1 expression
    pure (pure ":D") :: Maybe [String]Just [":D"]
  • (<*>) :: f (a -> b) -> f a -> f binfixl 4

    Sequential application.

    A few functors support an implementation of <*> that is more efficient than the default one.

    Example

    Used in combination with (Data.Functor.<$>), (<*>) can be used to build a record.

    Example1 expression
    data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}
    Example3 expressions
    produceFoo :: Applicative f => f FooproduceBar :: Applicative f => f BarproduceBaz :: Applicative f => f Baz
    Example2 expressions
    mkState :: Applicative f => f MyStatemkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
  • liftA2 :: (a -> b -> c) -> f a -> f b -> f c

    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.

    Example
    Example1 expression
    liftA2 (,) (Just 3) (Just 5)Just (3,5)
    Example1 expression
    liftA2 (+) [1, 2, 3] [4, 5, 6][5,6,7,6,7,8,7,8,9]
  • (*>) :: f a -> f b -> f binfixl 4

    Sequence actions, discarding the value of the first argument.

    Examples

    If used in conjunction with the Applicative instance for Maybe, you can chain Maybe computations, with a possible "early return" in case of Nothing.

    Example1 expression
    Just 2 *> Just 3Just 3
    Example1 expression
    Nothing *> Just 3Nothing

    Of course a more interesting use case would be to have effectful computations instead of just returning pure values.

    Example4 expressions
    import Data.Charimport GHC.Internal.Text.ParserCombinators.ReadPlet p = string "my name is " *> munch1 isAlpha <* eofreadP_to_S p "my name is Simon"[("Simon","")]
  • (<*) :: f a -> f b -> f ainfixl 4

    Sequence actions, discarding the value of the second argument.

Instances43Applicative, …
value(<**>) :: Applicative f => f a -> f (a -> b) -> f b
#

A variant of <*> with the types of the arguments reversed. It differs from flip (<*>) in that the effects are resolved in the order the arguments are presented.

Examples
Example1 expression
(<**>) (print 1) (id <$ print 2)12
Example1 expression
flip (<*>) (print 1) (id <$ print 2)21
Example1 expression
ZipList [4, 5, 6] <**> ZipList [(+1), (*2), (/3)]ZipList {getZipList = [5.0,10.0,2.0]}
valueliftA :: Applicative f => (a -> b) -> f a -> f b
#

Lift a function to actions. Equivalent to Functor's fmap but implemented using only Applicative's methods: liftA f a = pure f <*> a

As such this function may be used to implement a Functor instance from an Applicative one.

This function can be used to define `fmap = liftA`, if Applicative is already defined for a data type.

Examples

Using the Applicative instance for Lists:

Example1 expression
liftA (+1) [1, 2][2,3]

Or the Applicative instance for Maybe

Example1 expression
liftA (+1) (Just 3)Just 4
valueliftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
#

Lift a ternary function to actions.

valuethenA :: Applicative f => f a -> f b -> f b
#

Sequence two Applicative actions, discarding the result of the first one.

Defined as `thenA fa fb = (id fa) <* fb`.

This can be used to explicitly define `(*>) = thenA`, which is the default definition.

valuejoin :: Monad m => m (m a) -> m a
#

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
Example1 expression
join [[1, 2, 3], [4, 5, 6], [7, 8, 9]][1,2,3,4,5,6,7,8,9]
Example1 expression
join (Just (Just 3))Just 3

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.Internal.Conc.atomically :: STM a -> IO a

is used to run GHC.Conc.STM transactions atomically. So, by specializing the types of GHC.Internal.Conc.atomically and join to

GHC.Internal.Conc.atomically :: STM (IO b) -> IO (IO b)
join       :: IO (IO b)  -> IO b

we can compose them as

join . GHC.Internal.Conc.atomically :: STM (IO b) -> IO b

to run an GHC.Conc.STM transaction and the IO action it returns.

classclass Applicative m => Monad (m :: Type -> Type) where
#

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:

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:

The above laws imply:

and that pure and (<*>) satisfy the applicative functor laws.

The instances of Monad for GHC.List.List, Data.Maybe.Maybe and System.IO.IO defined in the Prelude satisfy these laws.

Methods

  • (>>=) :: m a -> (a -> m b) -> m binfixl 1

    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
    

    An alternative name for this function is 'bind', because it is used to introduce bindings in monadic contexts, but some people may refer to it as 'flatMap', which results from it being equivalent to

    \x f -> join (fmap f x) :: Monad m => m a -> (a -> m b) -> m b

    which can be seen as mapping a value with Monad m => m a -> m (m b) and then 'flattening' m (m b) to m b using join.

  • (>>) :: m a -> m b -> m binfixl 1

    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
    

    or in terms of (>>=) as

    as >>= const bs
  • return :: a -> m a

    Inject a value into the monadic type. This function should not be different from its default implementation as pure. The justification for the existence of this function is merely historic.

Instances36Monad, …
  • Monad NonEmptyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.NonEmpty · orphan
  • Monad IdentityDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Identity
  • Monad FirstDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Monoid
  • Monad LastDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Monoid
  • Monad DownDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Ord
  • Monad DualDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Monad ProductDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Monad SumDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Monad NoIODefined in ghc-internal-10.0.0 · GHC.Internal.GHCi
  • Monad Par1Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Monad MaybeDefined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monad STMDefined in ghc-internal-10.0.0 · GHC.Internal.STM
  • Monad QDefined in ghc-internal-10.0.0 · GHC.Internal.TH.Monad
  • Monad PDefined in ghc-internal-10.0.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • Monad ReadPDefined in ghc-internal-10.0.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • Monad ReadPrecDefined in ghc-internal-10.0.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • Monad SoloDefined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monad IODefined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monad []Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monad ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Monad U1Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Monad (ST s)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Monad.ST.Lazy.Imp
  • Monad (Either e)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Either
  • Monad (ST s)Defined in ghc-internal-10.0.0 · GHC.Internal.ST
  • Monoid a => Monad (Tuple2 a)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • ArrowApply a => Monad (ArrowMonad a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
  • Monad f => Monad (Ap f)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Monoid
  • Monad f => Monad (Alt f)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • Monad f => Monad (Rec1 f)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Monad m => Monad (Kleisli m a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
  • Monad m => Monad (StateT s m)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Functor.Utils
  • (Monoid a, Monoid b) => Monad (Tuple3 a b)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monad ((->) r)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • (Monad f, Monad g) => Monad (f :*: g)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • (Monoid a, Monoid b, Monoid c) => Monad (Tuple4 a b c)Defined in ghc-internal-10.0.0 · GHC.Internal.Base
  • Monad f => Monad (M1 i c f)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
value(=<<) :: Monad m => (a -> m b) -> m a -> m b
#

Same as >>=, but with the arguments interchanged.

as >>= f == f =<< as
valuewhen :: Applicative f => Bool -> f () -> f ()
#

Conditional execution of Applicative expressions. For example,

Examples
when debug (putStrLn "Debugging")

will output the string Debugging if the Boolean value debug is True, and otherwise do nothing.

Example1 expression
putStr "pi:" >> when False (print 3.14159)pi:
valuesequence :: Monad m => [m a] -> m [a]
#

Evaluate each action in the sequence from left to right, and collect the results.

valueliftM :: Monad m => (a1 -> r) -> m a1 -> m r
#

Promote a function to a monad. This is equivalent to fmap but specialised to Monads.

This function can be used to define `fmap = liftM`, if Monad is already defined for a data type.

valueliftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
#

Promote a function to a monad, scanning the monadic arguments from left to right.

This function can be used to define `liftA2 = liftM2`, if Monad is already defined for a data type.

Examples
Example1 expression
liftM2 (+) [0,1] [0,2][0,2,1,3]
Example1 expression
liftM2 (+) (Just 1) NothingNothing
Example1 expression
liftM2 (+) (+ 3) (* 2) 518
valueliftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
#

Promote a function to a monad, scanning the monadic arguments from left to right (cf. liftM2).

valueliftM4
  1. :: Monad m
  2. => a1 -> a2 -> a3 -> a4 -> r
  3. -> m a1
  4. -> m a2
  5. -> m a3
  6. -> m a4
  7. -> m r
#

Promote a function to a monad, scanning the monadic arguments from left to right (cf. liftM2).

valueliftM5
  1. :: Monad m
  2. => a1 -> a2 -> a3 -> a4 -> a5 -> r
  3. -> m a1
  4. -> m a2
  5. -> m a3
  6. -> m a4
  7. -> m a5
  8. -> m r
#

Promote a function to a monad, scanning the monadic arguments from left to right (cf. liftM2).

valueap :: Monad m => m (a -> b) -> m a -> m b
#

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

liftM<n> f x1 x2 ... xn

This function can be used to define `(*) = ap`, if Monad is already defined for a data type.

Examples
Example1 expression
pure (\x y z -> x + y * z) `ap` Just 1 `ap` Just 5 `ap` Just 10Just 51
valuethenM :: Monad m => m a -> m b -> m b
#

Sequence two monadic actions, discarding the result of the first one.

Defined as `thenM ma mb = ma >>= const mb`.

This can be used to define `(*>) = thenM`.

classclass Applicative f => Alternative (f :: Type -> Type) where
#

A monoid on applicative functors.

If defined, some and many should be the least solutions of the equations:

Examples
Example1 expression
Nothing <|> Just 42Just 42
Example1 expression
[1, 2] <|> [3, 4][1,2,3,4]
Example1 expression
empty <|> print (2^15)32768

Methods

  • empty :: f a

    The identity of <|>

    empty <|> a     == a
    a     <|> empty == a
  • (<|>) :: f a -> f a -> f ainfixl 3

    An associative binary operation

  • some :: f a -> f [a]

    One or more.

    Examples
    Example1 expression
    some (putStr "la")lalalalalalalalala... * goes on forever *
    Example1 expression
    some Nothingnothing
    Example1 expression
    take 5 <$> some (Just 1)* hangs forever *

    Note that this function can be used with Parsers based on Applicatives. In that case some parser will attempt to parse parser one or more times until it fails.

  • many :: f a -> f [a]

    Zero or more.

    Examples
    Example1 expression
    many (putStr "la")lalalalalalalalala... * goes on forever *
    Example1 expression
    many NothingJust []
    Example1 expression
    take 5 <$> many (Just 1)* hangs forever *

    Note that this function can be used with Parsers based on Applicatives. In that case many parser will attempt to parse parser zero or more times until it fails.

Instances19Alternative, …
classclass (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
#

Monads that also support choice and failure.

Methods

  • mzero :: m a

    The identity of mplus. It should also satisfy the equations

    mzero >>= f  =  mzero
    v >> mzero   =  mzero

    The default definition is

    mzero = empty
    
  • mplus :: m a -> m a -> m a

    An associative operation. The default definition is

    mplus = (<|>)
    
Instances16MonadPlus, …
  • MonadPlus MaybeDefined in ghc-internal-10.0.0 · GHC.Internal.Base

    Picks the leftmost Just value, or, alternatively, Nothing.

  • MonadPlus STMDefined in ghc-internal-10.0.0 · GHC.Internal.STM

    Takes the first non-retrying STM action.

  • MonadPlus PDefined in ghc-internal-10.0.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • MonadPlus ReadPDefined in ghc-internal-10.0.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • MonadPlus ReadPrecDefined in ghc-internal-10.0.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • MonadPlus IODefined in ghc-internal-10.0.0 · GHC.Internal.Base

    Takes the first non-throwing IO action's result. mzero throws an exception.

  • MonadPlus []Defined in ghc-internal-10.0.0 · GHC.Internal.Base

    Combines lists by concatenation, starting from the empty list.

  • MonadPlus ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • MonadPlus U1Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
  • MonadPlus f => MonadPlus (Ap f)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Monoid
  • MonadPlus f => MonadPlus (Alt f)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Semigroup.Internal
  • MonadPlus f => MonadPlus (Rec1 f)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • MonadPlus m => MonadPlus (Kleisli m a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
  • (MonadPlus f, MonadPlus g) => MonadPlus (f :*: g)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • MonadPlus f => MonadPlus (M1 i c f)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
datadata NonEmpty a
#

Non-empty (and non-strict) list type.

Constructors

  • a :| [a]infixr 5
Instances20Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
valuefoldr :: (a -> b -> b) -> b -> [a] -> b
#

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)...)
valuebuild :: (forall b. (a -> b -> b) -> b -> b) -> [a]
#

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.

valueaugment :: (forall b. (a -> b -> b) -> b -> b) -> [a] -> [a]
#

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.

valuemap :: (a -> b) -> [a] -> [b]
#

\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, ...]

this means that map id == id

Examples
Example1 expression
map (+1) [1, 2, 3][2,3,4]
Example1 expression
map id [1, 2, 3][1,2,3]
Example1 expression
map (\n -> 3 * n + 1) [1, 2, 3][4,7,10]
valuemapFB :: (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst
#
value(++) :: [a] -> [a] -> [a]
#

(++) appends 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.

Performance considerations

This function takes linear time in the number of elements of the first list. Thus it is better to associate repeated applications of (++) to the right (which is the default behaviour): xs ++ (ys ++ zs) or simply xs ++ ys ++ zs, but not (xs ++ ys) ++ zs. For the same reason GHC.Internal.Data.List.concat = GHC.Internal.Data.List.foldr (++) [] has linear performance, while GHC.Internal.Data.List.foldl (++) [] is prone to quadratic slowdown

Examples
Example1 expression
[1, 2, 3] ++ [4, 5, 6][1,2,3,4,5,6]
Example1 expression
[] ++ [1, 2, 3][1,2,3]
Example1 expression
[3, 2, 1] ++ [][3,2,1]
valueotherwise :: Bool
#

otherwise is defined as the value True. It helps to make guards more readable. eg.

 f x | x < 0     = ...
     | otherwise = ...
typetype String = [Char]
#

String is an alias for a list of characters.

String constants in Haskell are values of type String. That means if you write a string literal like "hello world", it will have the type [Char], which is the same as String.

Note: You can ask the compiler to automatically infer different types with the -XOverloadedStrings language extension, for example "hello world" :: Text. See Data.String.IsString for more information.

Because String is just a list of characters, you can use normal list functions to do basic string manipulation. See Data.List for operations on lists.

Performance considerations

[Char] is a relatively memory-inefficient type. It is a linked list of boxed word-size characters, internally it looks something like:

╭─────┬───┬──╮  ╭─────┬───┬──╮  ╭─────┬───┬──╮  ╭────╮
│ (:) │   │ ─┼─>│ (:) │   │ ─┼─>│ (:) │   │ ─┼─>│ [] │
╰─────┴─┼─┴──╯  ╰─────┴─┼─┴──╯  ╰─────┴─┼─┴──╯  ╰────╯
        v               v               v
       'a'             'b'             'c'

The String "abc" will use 5*3+1 = 16 (in general 5n+1) words of space in memory.

Furthermore, operations like (++) (string concatenation) are O(n) (in the left argument).

For historical reasons, the base library uses String in a lot of places for the conceptual simplicity, but library code dealing with user-data should use the text package for Unicode text, or the the bytestring package for binary data.

valueord :: Char -> Int
#

The Prelude.fromEnum method restricted to the type Data.Char.Char.

valueid :: a -> a
#

Identity function.

id x = x

This function might seem useless at first glance, but it can be very useful in a higher order context.

Examples
Example1 expression
length $ filter id [True, True, False, True]3
Example1 expression
Just (Just 3) >>= idJust 3
Example1 expression
foldr id 0 [(^3), (*5), (+2)]1000
valueassert :: Bool -> a -> a
#

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.

datadata Opaque
#

Constructors

  • forall a. O a
valueconst :: a -> b -> a
#

const x y always evaluates to x, ignoring its second argument.

const x = \_ -> x

This function might seem useless at first glance, but it can be very useful in a higher order context.

Examples
Example1 expression
const 42 "hello"42
Example1 expression
map (const 42) [0..3][42,42,42,42]
value(.) :: (b -> c) -> (a -> b) -> a -> c
#

Right to left function composition.

Property
(f . g) x = f (g x)
Property
f . id = f = id . f
Examples
Example1 expression
map ((*2) . length) [[], [0, 1, 2], [0]][0,6,2]
Example1 expression
foldr (.) id [(+1), (*3), (^3)] 225
Example1 expression
let (...) = (.).(.) in ((*2)...(+)) 5 1030
valueflip :: (a -> b -> c) -> b -> a -> c
#

flip f takes its (first) two arguments in the reverse order of f.

Property
flip f x y = f y x
Property
flip . flip = id
Examples
Example1 expression
flip (++) "hello" "world""worldhello"
Example1 expression
let (.>) = flip (.) in (+1) .> show $ 5"6"
value($) :: (a -> b) -> a -> b
#

($) is the function application operator.

Applying ($) to a function f and an argument x gives the same result as applying f to x directly. The definition is akin to this:

($) :: (a -> b) -> a -> b
($) f x = f x

This is id specialized from a -> a to (a -> b) -> (a -> b) which by the associativity of (->) is the same as (a -> b) -> a -> b.

On the face of it, this may appear pointless! But it's actually one of the most useful and important operators in Haskell.

The order of operations is very different between ($) and normal function application. Normal function application has precedence 10 - higher than any operator - and associates to the left. So these two definitions are equivalent:

expr = min 5 1 + 5
expr = ((min 5) 1) + 5

($) has precedence 0 (the lowest) and associates to the right, so these are equivalent:

expr = min 5 $ 1 + 5
expr = (min 5) (1 + 5)
Examples

A common use cases of ($) is to avoid parentheses in complex expressions.

For example, instead of using nested parentheses in the following Haskell function:

-- | Sum numbers in a string: strSum "100  5 -7" == 98
strSum :: String -> Int
strSum s = sum (mapMaybe readMaybe (words s))

we can deploy the function application operator:

-- | Sum numbers in a string: strSum "100  5 -7" == 98
strSum :: String -> Int
strSum s = sum $ mapMaybe readMaybe $ words s

($) is also used as a section (a partially applied operator), in order to indicate that we wish to apply some yet-unspecified function to a given value. For example, to apply the argument 5 to a list of functions:

applyFive :: [Int]
applyFive = map ($ 5) [(+1), (2^)]
>>> [6, 32]
Technical Remark (Representation Polymorphism)

($) is fully representation-polymorphic. This allows it to also be used with arguments of unlifted and even unboxed kinds, such as unboxed integers:

fastMod :: Int -> Int -> Int
fastMod (I# x) (I# m) = I# $ remInt# x m
value($!) :: (a -> b) -> a -> b
#

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.

valueuntil :: (a -> Bool) -> (a -> a) -> a -> a
#

until p f yields the result of applying f until p holds.

valueasTypeOf :: a -> a -> a
#

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.

valuegetTag :: DataToTag a => a -> Int#
#

Returns the tag of a constructor application; this function was once used by the deriving code for Eq, Ord and Enum.

valuequotInt :: Int -> Int -> Int
#

Used to implement quot for the Integral typeclass. This performs integer division on its two parameters, truncated towards zero.

Example
Example1 expression
quotInt 10 25
Example1 expression
quot 10 25
valueremInt :: Int -> Int -> Int
#

Used to implement rem for the Integral typeclass. This gives the remainder after integer division of its two parameters, satisfying

((x `quot` y) * y) + (x `rem` y) == x
Example
Example1 expression
remInt 3 21
Example1 expression
rem 3 21
valuedivInt :: Int -> Int -> Int
#

Used to implement div for the Integral typeclass. This performs integer division on its two parameters, truncated towards negative infinity.

Example
Example1 expression
10 `divInt` 25
Example1 expression
10 `div` 25
valuemodInt :: Int -> Int -> Int
#

Used to implement mod for the Integral typeclass. This performs the modulo operation, satisfying

((x `div` y) * y) + (x `mod` y) == x
Example
Example1 expression
7 `modInt` 31
Example1 expression
7 `mod` 31
valuequotRemInt :: Int -> Int -> (Int, Int)
#

Used to implement quotRem for the Integral typeclass. This gives a tuple equivalent to

(quot x y, mod x y)
Example
Example1 expression
quotRemInt 10 2(5,0)
Example1 expression
quotRem 10 2(5,0)
valuedivModInt :: Int -> Int -> (Int, Int)
#

Used to implement divMod for the Integral typeclass. This gives a tuple equivalent to

(div x y, mod x y)
Example
Example1 expression
divModInt 10 2(5,0)
Example1 expression
divMod 10 2(5,0)
valueshift_mask :: Int# -> Int# -> Int#
#

This function is used to implement branchless shifts. If the number of bits to shift is greater than or equal to the type size in bits, then the shift must return 0. Instead of doing a test, we use a mask obtained via this function which is branchless too.

shift_mask m b | b < m = 0xFF..FF | otherwise = 0

valueshiftL# :: Word# -> Int# -> Word#
#

Shift the argument left by the specified number of bits (which must be non-negative).

valueshiftRL# :: Word# -> Int# -> Word#
#

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#)

valueiShiftL# :: Int# -> Int# -> Int#
#

Shift the argument left by the specified number of bits (which must be non-negative).

valueiShiftRA# :: Int# -> Int# -> Int#
#

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)

valueiShiftRL# :: Int# -> Int# -> Int#
#

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)