HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulebase-4.20.2.0Haskell2010

GHC.Base

Basic data types and classes.

  • 110 types
  • 15 classes
  • 1503 values
  • Packagebase-4.20.2.0
  • Exports1630
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceBase.hs
datadata SPEC
#

SPEC is used by GHC in the SpecConstr pass in order to inform the compiler when to be particularly aggressive. In particular, it tells GHC to specialize regardless of size or the number of specializations. However, not all loops fall into this category.

Libraries can specify this by using SPEC data type to inform which loops should be aggressively specialized. For example, instead of

loop x where loop arg = ...

write

loop SPEC x where loop !_ arg = ...

There is no semantic difference between SPEC and SPEC2, we just need a type with two constructors lest it is optimised away before SpecConstr.

This type is reexported from GHC.Exts since GHC 9.0 and base-4.15. For compatibility with earlier releases import it from GHC.Types in ghc-prim package.

typetype Void# = (# #)
#

Deprecated. Void# is now an alias for the unboxed tuple (# #).

datadata TYPE (a :: RuntimeRep)
#
Instances285HasResolution, Category, Generic1, Bifoldable1, Eq2, Ord2, …
datadata DictBox (a :: Constraint)
#

Data type Dict provides a simple way to wrap up a (lifted) constraint as a type

Constructors

datadata Bool
#
Instances18Bounded, Enum, Eq, Data, Ord, Read, …
  • Bounded BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Enum BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Eq BoolDefined in ghc-prim-0.12.0 · GHC.Classes
  • Data BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Ord BoolDefined in ghc-prim-0.12.0 · GHC.Classes
  • Read BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Show BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Show
  • Ix BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Generic BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Bits BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Bits

    Interpret Bool as 1-bit bit-field

  • FiniteBits BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Bits
  • Storable BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • SingKind BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • SingI 'FalseDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • SingI 'TrueDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep Bool = D1 ('MetaData "Bool" "GHC.Types" "ghc-prim" 'False) (C1 ('MetaCons "False" 'PrefixI 'False) U1 :+: C1 ('MetaCons "True" 'PrefixI 'False) U1)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type DemoteRep Bool = BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • data Sing
    • STrue :: R:SingBoola 'True
    • SFalse :: R:SingBoola 'False
    Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
datadata Char
#

The character type Char represents Unicode codespace and its elements are code points as in definitions D9 and D10 of the Unicode Standard.

Character literals in Haskell are single-quoted: 'Q', 'Я' or 'Ω'. To represent a single quote itself use '\'', and to represent a backslash use '\\'. The full grammar can be found in the section 2.6 of the Haskell 2010 Language Report.

To specify a character by its code point one can use decimal, hexadecimal or octal notation: '\65', '\x41' and '\o101' are all alternative forms of 'A'. The largest code point is '\x10ffff'.

There is a special escape syntax for ASCII control characters:

Escape

Alternatives

Meaning

'\NUL'

'\0'

null character

'\SOH'

'\1'

start of heading

'\STX'

'\2'

start of text

'\ETX'

'\3'

end of text

'\EOT'

'\4'

end of transmission

'\ENQ'

'\5'

enquiry

'\ACK'

'\6'

acknowledge

'\BEL'

'\7'

,

'\a'

bell (alert)

'\BS'

'\8'

,

'\b'

backspace

'\HT'

'\9'

,

'\t'

horizontal tab

'\LF'

'\10'

,

'\n'

line feed (new line)

'\VT'

'\11'

,

'\v'

vertical tab

'\FF'

'\12'

,

'\f'

form feed

'\CR'

'\13'

,

'\r'

carriage return

'\SO'

'\14'

shift out

'\SI'

'\15'

shift in

'\DLE'

'\16'

data link escape

'\DC1'

'\17'

device control 1

'\DC2'

'\18'

device control 2

'\DC3'

'\19'

device control 3

'\DC4'

'\20'

device control 4

'\NAK'

'\21'

negative acknowledge

'\SYN'

'\22'

synchronous idle

'\ETB'

'\23'

end of transmission block

'\CAN'

'\24'

cancel

'\EM'

'\25'

end of medium

'\SUB'

'\26'

substitute

'\ESC'

'\27'

escape

'\FS'

'\28'

file separator

'\GS'

'\29'

group separator

'\RS'

'\30'

record separator

'\US'

'\31'

unit separator

'\SP'

'\32'

,

' '

space

'\DEL'

'\127'

delete

Data.Char provides utilities to work with Char.

Constructors

Instances25Bounded, Enum, Data, Read, Ix, Storable, …
datadata Double
#

Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.

Constructors

Instances25Enum, Floating, Fractional, Data, Num, Read, …
  • Enum DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    fromEnum just truncates its argument, beware of all sorts of overflows.

    List generators have extremely peculiar behavior, mandated by Haskell Report 2010:

    Example1 expression
    [0..1.5][0.0,1.0,2.0]
  • Eq DoubleDefined in ghc-prim-0.12.0 · GHC.Classes

    Note that due to the presence of NaN, Double's Eq instance does not satisfy reflexivity.

    Example1 expression
    0/0 == (0/0 :: Double)False

    Also note that Double's Eq instance does not satisfy substitutivity:

    Example2 expressions
    0 == (-0 :: Double)Truerecip 0 == recip (-0 :: Double)False
  • Floating DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float
  • Fractional DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.

    Example4 expressions
    0 == (-0 :: Double)Truerecip 0 == recip (-0 :: Double)Falsemap (/ 0) [-1, 0, 1][-Infinity,NaN,Infinity]map (* 0) $ map (/ 0) [-1, 0, 1][NaN,NaN,NaN]
  • Data DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:

    Example3 expressions
    (0.1 + 0.1) + 0.4 == 0.1 + (0.1 + 0.4)False(0.1 + 0.2) * 0.3 == 0.1 * 0.3 + 0.2 * 0.3False(0.1 * 0.1) * 0.3 == 0.1 * (0.1 * 0.3)False
  • Ord DoubleDefined in ghc-prim-0.12.0 · GHC.Classes

    IEEE 754 Double-precision type includes not only numbers, but also positive and negative infinities and a special element called NaN (which can be quiet or signal).

    IEEE 754-2008, section 5.11 requires that if at least one of arguments of <=, <, >, >= is NaN then the result of the comparison is False, and instance Ord Double complies with this requirement. This violates the reflexivity: both NaN <= NaN and NaN >= NaN are False.

    IEEE 754-2008, section 5.10 defines totalOrder predicate. Unfortunately, compare on Doubles violates the IEEE standard and does not define a total order. More specifically, both compare NaN x and compare x NaN always return GT.

    Thus, users must be extremely cautious when using instance Ord Double. For instance, one should avoid ordered containers with keys represented by Double, because data loss and corruption may happen. An IEEE-compliant compare is available in fp-ieee package as TotallyOrdered newtype.

    Moving further, the behaviour of min and max with regards to NaN is also non-compliant. IEEE 754-2008, section 5.3.1 defines that quiet NaN should be treated as a missing data by minNum and maxNum functions, for example, minNum(NaN, 1) = minNum(1, NaN) = 1. Some languages such as Java deviate from the standard implementing minNum(NaN, 1) = minNum(1, NaN) = NaN. However, min / max in base are even worse: min NaN 1 is 1, but min 1 NaN is NaN.

    IEEE 754-2008 compliant min / max can be found in ieee754 package under minNum / maxNum names. Implementations compliant with minimumNumber / maximumNumber from a newer IEEE 754-2019, section 9.6 are available from fp-ieee package.

  • Read DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    Beware that toRational generates garbage for non-finite arguments:

    Example2 expressions
    toRational (1/0)179769313 (and 300 more digits...) % 1toRational (0/0)269653970 (and 300 more digits...) % 1
  • RealFloat DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float
  • RealFrac DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    Beware that results for non-finite arguments are garbage:

    Example2 expressions
    [ f x | f <- [round, floor, ceiling], x <- [-1/0, 0/0, 1/0] ] :: [Int][0,0,0,0,0,0,0,0,0]map properFraction [-1/0, 0/0, 1/0] :: [(Int, Double)][(0,0.0),(0,0.0),(0,0.0)]

    and get even more non-sensical if you ask for Integer instead of Int.

  • Show DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan
  • Storable DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • PrintfArg DoubleDefined in base-4.20.2.0 · Text.Printf
  • Generic1 (URec Double)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Foldable UDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Foldable
  • Traversable UDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Traversable
  • Functor (URec Double)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Show (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Generic (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep (URec Double p) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UDouble" 'PrefixI 'True) (S1 ('MetaSel ('Just "uDouble#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UDouble))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep1 (URec Double) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UDouble" 'PrefixI 'True) (S1 ('MetaSel ('Just "uDouble#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UDouble))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • data URec DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics

    Used for marking occurrences of Double#

datadata Float
#

Single-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE single-precision type.

Constructors

Instances25Enum, Floating, Fractional, Data, Num, Read, …
  • Enum FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    fromEnum just truncates its argument, beware of all sorts of overflows.

    List generators have extremely peculiar behavior, mandated by Haskell Report 2010:

    Example1 expression
    [0..1.5 :: Float][0.0,1.0,2.0]
  • Eq FloatDefined in ghc-prim-0.12.0 · GHC.Classes

    Note that due to the presence of NaN, Float's Eq instance does not satisfy reflexivity.

    Example1 expression
    0/0 == (0/0 :: Float)False

    Also note that Float's Eq instance does not satisfy extensionality:

    Example2 expressions
    0 == (-0 :: Float)Truerecip 0 == recip (-0 :: Float)False
  • Floating FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float
  • Fractional FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.

    Example4 expressions
    0 == (-0 :: Float)Truerecip 0 == recip (-0 :: Float)Falsemap (/ 0) [-1, 0, 1 :: Float][-Infinity,NaN,Infinity]map (* 0) $ map (/ 0) [-1, 0, 1 :: Float][NaN,NaN,NaN]
  • Data FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:

    Example3 expressions
    (0.1 + 0.1 :: Float) + 0.5 == 0.1 + (0.1 + 0.5)False(0.1 + 0.2 :: Float) * 0.9 == 0.1 * 0.9 + 0.2 * 0.9False(0.1 * 0.1 :: Float) * 0.9 == 0.1 * (0.1 * 0.9)False
  • Ord FloatDefined in ghc-prim-0.12.0 · GHC.Classes

    See instance Ord Double for discussion of deviations from IEEE 754 standard.

  • Read FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    Beware that toRational generates garbage for non-finite arguments:

    Example2 expressions
    toRational (1/0 :: Float)340282366920938463463374607431768211456 % 1toRational (0/0 :: Float)510423550381407695195061911147652317184 % 1
  • RealFloat FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float
  • RealFrac FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan

    Beware that results for non-finite arguments are garbage:

    Example2 expressions
    [ f x | f <- [round, floor, ceiling], x <- [-1/0, 0/0, 1/0 :: Float] ] :: [Int][0,0,0,0,0,0,0,0,0]map properFraction [-1/0, 0/0, 1/0] :: [(Int, Float)][(0,0.0),(0,0.0),(0,0.0)]

    and get even more non-sensical if you ask for Integer instead of Int.

  • Show FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Float · orphan
  • Storable FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • PrintfArg FloatDefined in base-4.20.2.0 · Text.Printf
  • Generic1 (URec Float)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Foldable UFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Foldable
  • Traversable UFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Traversable
  • Functor (URec Float)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Show (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Generic (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep (URec Float p) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UFloat" 'PrefixI 'True) (S1 ('MetaSel ('Just "uFloat#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UFloat))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep1 (URec Float) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UFloat" 'PrefixI 'True) (S1 ('MetaSel ('Just "uFloat#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) UFloat))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • data URec FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics

    Used for marking occurrences of Float#

datadata Int
#

A fixed-precision integer type with at least the range [-2^29 .. 2^29-1]. The exact range for a given implementation can be determined by using Prelude.minBound and Prelude.maxBound from the Prelude.Bounded class.

Constructors

Instances26Bounded, Enum, Integral, Data, Num, Read, …
datadata Word
#

A Word is an unsigned integral type, with the same size as Int.

Constructors

Instances26Bounded, Enum, Integral, Data, Num, Read, …
datadata List a
#

The builtin linked list type.

In Haskell, lists are one of the most important data types as they are often used analogous to loops in imperative programming languages. These lists are singly linked, which makes them unsuited for operations that require \mathcal{O}(1) access. Instead, they are intended to be traversed.

You can use List a or [a] in type signatures:

length :: [a] -> Int

or

length :: List a -> Int

They are fully equivalent, and List a will be normalised to [a].

Usage

Lists are constructed recursively using the right-associative constructor operator (or cons) (:) :: a -> [a] -> [a], which prepends an element to a list, and the empty list [].

(1 : 2 : 3 : []) == (1 : (2 : (3 : []))) == [1, 2, 3]

Lists can also be constructed using list literals of the form [x_1, x_2, ..., x_n] which are syntactic sugar and, unless -XOverloadedLists is enabled, are translated into uses of (:) and []

String literals, like "I 💜 hs", are translated into Lists of characters, ['I', ' ', '💜', ' ', 'h', 's'].

Implementation

Internally and in memory, all the above are represented like this, with arrows being pointers to locations in memory.

╭───┬───┬──╮   ╭───┬───┬──╮   ╭───┬───┬──╮   ╭────╮
│(:)│   │ ─┼──>│(:)│   │ ─┼──>│(:)│   │ ─┼──>│ [] │
╰───┴─┼─┴──╯   ╰───┴─┼─┴──╯   ╰───┴─┼─┴──╯   ╰────╯
      v              v              v
      1              2              3
Examples
>>> ['H', 'a', 's', 'k', 'e', 'l', 'l']
"Haskell"
>>> 1 : [4, 1, 5, 9]
[1,4,1,5,9]
>>> [] : [] : []
[[],[]]
Instances30Monad, Functor, MonadFix, MonadFail, Applicative, Foldable, …
datadata Ordering
#
Instances12Bounded, Enum, Eq, Data, Ord, Read, …
classclass a ~# b => (~~) (a :: k0) (b :: k1)
#

Lifted, heterogeneous equality. By lifted, we mean that it can be bogus (deferred type error). By heterogeneous, the two types a and b might have different kinds. Because ~~ can appear unexpectedly in error messages to users who do not care about the difference between heterogeneous equality ~~ and homogeneous equality ~, this is printed as ~ unless -fprint-equality-relations is set.

In 0.7.0, the fixity was set to infix 4 to match the fixity of :~~:.

classclass a ~ b => (~) (a :: k) (b :: k)
#

Lifted, homogeneous equality. By lifted, we mean that it can be bogus (deferred type error). By homogeneous, the two types a and b must have the same kinds.

classclass a ~ b => Coercible (a :: k) (b :: k)
#

Coercible is a two-parameter class that has instances for types a and b if the compiler can infer that they have the same representation. This class does not have regular instances; instead they are created on-the-fly during type-checking. Trying to manually declare an instance of Coercible is an error.

Nevertheless one can pretend that the following three kinds of instances exist. First, as a trivial base-case:

instance Coercible a a

Furthermore, for every type constructor there is an instance that allows to coerce under the type constructor. For example, let D be a prototypical type constructor (data or newtype) with three type arguments, which have roles nominal, representational resp. phantom. Then there is an instance of the form

instance Coercible b b' => Coercible (D a b c) (D a b' c')

Note that the nominal type arguments are equal, the representational type arguments can differ, but need to have a Coercible instance themself, and the phantom type arguments can be changed arbitrarily.

The third kind of instance exists for every newtype NT = MkNT T and comes in two variants, namely

instance Coercible a T => Coercible a NT
instance Coercible T b => Coercible NT b

This instance is only usable if the constructor MkNT is in scope.

If, as a library author of a type constructor like Set a, you want to prevent a user of your module to write coerce :: Set T -> Set NT, you need to set the role of Set's type parameter to nominal, by writing

type role Set nominal

For more details about this feature, please refer to Safe Coercions by Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones and Stephanie Weirich.

datadata Symbol
#

(Kind) This is the kind of type-level symbols.

Instances7SingKind, TestCoercion, TestEquality, SingI, Compare, DemoteRep, …
  • SingKind SymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • TestCoercion SSymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • TestEquality SSymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • KnownSymbol a => SingI aDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Compare a b = CmpSymbol a bDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Ord
  • type DemoteRep Symbol = StringDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • data SingDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
datadata RuntimeRep
#

GHC maintains a property that the kind of all inhabited types (as distinct from type constructors or type-level data) tells us the runtime representation of values of that type. This datatype encodes the choice of runtime value. Note that TYPE is parameterised by RuntimeRep; this is precisely what we mean by the fact that a type's kind encodes the runtime representation.

For boxed values (that is, values that are represented by a pointer), a further distinction is made, between lifted types (that contain ⊥), and unlifted ones (that don't).

Constructors

Instances1Show
datadata Levity
#

Whether a boxed type is lifted or unlifted.

Instances3Bounded, Enum, Show
  • Bounded LevityDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Enum LevityDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Show LevityDefined in ghc-internal-9.1003.0 · GHC.Internal.Show
newtypenewtype IO a
#

A value of type IO a is a computation which, when performed, does some I/O before returning a value of type a.

There is really only one way to "perform" an I/O action: bind it to Main.main in your program. When your program is run, the I/O will be performed. It isn't possible to perform I/O from an arbitrary function, unless that function is itself in the IO monad and called at some point, directly or indirectly, from Main.main.

IO is a monad, so IO actions can be combined using either the do-notation or the Prelude.>> and Prelude.>>= operations from the Prelude.Monad class.

Constructors

Instances13Monad, Functor, MonadFix, MonadFail, Applicative, GHCiSandboxIO, …
  • Monad IODefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor IODefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • MonadFix IODefined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.Fix
  • MonadFail IODefined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.Fail
  • Applicative IODefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • GHCiSandboxIO IODefined in ghc-internal-9.1003.0 · GHC.Internal.GHCi
  • Alternative IODefined in ghc-internal-9.1003.0 · GHC.Internal.Base

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

  • MonadPlus IODefined in ghc-internal-9.1003.0 · GHC.Internal.Base

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

  • MonadIO IODefined in base-4.20.2.0 · Control.Monad.IO.Class
  • Semigroup a => Semigroup (IO a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid a => Monoid (IO a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • a ~ () => HPrintfType (IO a)Defined in base-4.20.2.0 · Text.Printf
  • a ~ () => PrintfType (IO a)Defined in base-4.20.2.0 · Text.Printf
typetype ZeroBitRep = 'TupleRep '[]
#

The runtime representation of a zero-width tuple, represented by no bits at all

typetype LiftedRep = 'BoxedRep 'Lifted
#

The runtime representation of lifted types.

Instances22Category, Arrow, ArrowApply, ArrowChoice, ArrowLoop, Monad, …

The kind of boxed, unlifted values, for example Array# or a user-defined unlifted data type, using -XUnliftedDataTypes.

typetype Type = TYPE LiftedRep
#

The kind of types with lifted values. For example Int :: Type.

familytype family Any :: k where
#

The type constructor Any is type to which you can unsafely coerce any lifted type, and back. More concretely, for a lifted type t and value x :: t, unsafeCoerce (unsafeCoerce x :: Any) :: t is equivalent to x.

datadata Addr#
#

An arbitrary machine address assumed to point outside the garbage-collected heap.

datadata ByteArray#
#

A boxed, unlifted datatype representing a region of raw memory in the garbage-collected heap, which is not scanned for pointers during garbage collection.

It is created by freezing a MutableByteArray# with unsafeFreezeByteArray#. Freezing is essentially a no-op, as MutableByteArray# and ByteArray# share the same heap structure under the hood.

The immutable and mutable variants are commonly used for scenarios requiring high-performance data structures, like Text, Primitive Vector, Unboxed Array, and ShortByteString.

Another application of fundamental importance is Integer, which is backed by ByteArray#.

The representation on the heap of a Byte Array is:

+------------+-----------------+-----------------------+
|            |                 |                       |
|   HEADER   | SIZE (in bytes) |       PAYLOAD         |
|            |                 |                       |
+------------+-----------------+-----------------------+

To obtain a pointer to actual payload (e.g., for FFI purposes) use byteArrayContents# or mutableByteArrayContents#.

Alternatively, enabling the UnliftedFFITypes extension allows to mention ByteArray# and MutableByteArray# in FFI type signatures directly.

datadata BCO
#

Primitive bytecode type.

datadata MutableByteArray# a
#

A mutable ByteAray#. It can be created in three ways:

  • newByteArray#: Create an unpinned array.

  • newPinnedByteArray#: This will create a pinned array,

  • newAlignedPinnedByteArray#: This will create a pinned array, with a custom alignment.

Unpinned arrays can be moved around during garbage collection, so you must not store or pass pointers to these values if there is a chance for the garbage collector to kick in. That said, even unpinned arrays can be passed to unsafe FFI calls, because no garbage collection happens during these unsafe calls (see Guaranteed Call Safety in the GHC Manual). For safe FFI calls, byte arrays must be not only pinned, but also kept alive by means of the keepAlive# function for the duration of a call (that's because garbage collection cannot move a pinned array, but is free to scrap it altogether).

datadata MVar# a (b :: TYPE ('BoxedRep l))
#

A shared mutable variable (not the same as a MutVar#!). (Note: in a non-concurrent implementation, (MVar# a) can be represented by (MutVar# (Maybe a)).)

datadata IOPort# a (b :: TYPE ('BoxedRep l))
#

A shared I/O port is almost the same as an MVar#. The main difference is that IOPort has no deadlock detection or deadlock breaking code that forcibly releases the lock.

datadata MutVar# a (b :: TYPE ('BoxedRep l))
#

A MutVar# behaves like a single-element mutable array.

datadata RealWorld
#

RealWorld is deeply magical. It is primitive, but it is not unlifted (hence ptrArg). We never manipulate values of type RealWorld; it's only used in the type system, to parameterise State#.

datadata State# a
#

State# is the primitive, unlifted type of states. It has one type parameter, thus State# RealWorld, or State# s, where s is a type variable. The only purpose of the type parameter is to keep different state threads separate. It is represented by nothing at all.

datadata Proxy# (a :: k)
#

The type constructor Proxy# is used to bear witness to some type variable. It's used when you want to pass around proxy values for doing things like modelling type applications. A Proxy# is not only unboxed, it also has a polymorphic kind, and has no runtime representation, being totally free.

datadata ThreadId#
#

(In a non-concurrent implementation, this can be a singleton type, whose (unique) value is returned by myThreadId#. The other operations can be omitted.)

datadata StackSnapshot#
#

Haskell representation of a StgStack* that was created (cloned) with a function in GHC.Stack.CloneStack. Please check the documentation in that module for more detailed explanations.

datadata PromptTag# a
#

See GHC.Prim#continuations.

datadata FUN (n :: Multiplicity) (a :: TYPE q) (b :: TYPE r)
#

The builtin function type, written in infix form as a % m -> b. Values of this type are functions taking inputs of type a and producing outputs of type b. The multiplicity of the input is m.

Note that FUN m a b permits representation polymorphism in both a and b, so that types like Int# -> Int# can still be well-kinded.

Instances14Category, Show, Semigroup, Monoid, Arrow, ArrowApply, …
  • Category (->)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Category
  • Show (a -> b)Defined in base-4.20.2.0 · Text.Show.Functions · orphan
  • Semigroup b => Semigroup (a -> b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid b => Monoid (a -> b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Arrow (->)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • ArrowApply (->)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • ArrowChoice (->)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • ArrowLoop (->)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • (PrintfArg a, HPrintfType r) => HPrintfType (a -> r)Defined in base-4.20.2.0 · Text.Printf
  • (PrintfArg a, PrintfType r) => PrintfType (a -> r)Defined in base-4.20.2.0 · Text.Printf
  • Monad ((->) r)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor ((->) r)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • MonadFix ((->) r)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.Fix
  • Applicative ((->) r)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
datadata TYPE (a :: RuntimeRep)
#
Instances285HasResolution, Category, Generic1, Bifoldable1, Eq2, Ord2, …

The token used in the implementation of the IO monad as a state monad. It does not pass any information at runtime. See also runRW#.

valuevoid# :: (# #)
#

This is an alias for the unboxed unit tuple constructor. In earlier versions of GHC, void# was a value of the primitive type Void#, which is now defined to be (# #).

valueseq :: a -> b -> b
#

The value of seq a b is bottom if a is bottom, and otherwise equal to b. In other words, it evaluates the first argument a to weak head normal form (WHNF). seq is usually introduced to improve performance by avoiding unneeded laziness.

A note on evaluation order: the expression seq a b does not guarantee that a will be evaluated before b. The only guarantee given by seq is that the both a and b will be evaluated before seq returns a value. In particular, this means that b may be evaluated before a. If you need to guarantee a specific order of evaluation, you must use the function pseq from the "parallel" package.

valuecoerce :: Coercible a b => a -> b
#

The function coerce allows you to safely convert between values of types that have the same representation with no run-time overhead. In the simplest case you can use it instead of a newtype constructor, to go from the newtype's concrete type to the abstract type. But it also works in more complicated settings, e.g. converting a list of newtypes to a list of concrete types.

When used in conversions involving a newtype wrapper, make sure the newtype constructor is in scope.

This function is representation-polymorphic, but the RuntimeRep type argument is marked as Inferred, meaning that it is not available for visible type application. This means the typechecker will accept coerce @Int @Age 42.

Examples
Example5 expressions
newtype TTL = TTL Int deriving (Eq, Ord, Show)newtype Age = Age Int deriving (Eq, Ord, Show)coerce (Age 42) :: TTLTTL 42coerce (+ (1 :: Int)) (Age 42) :: TTLTTL 43coerce (map (+ (1 :: Int))) [Age 42, Age 24] :: [TTL][TTL 43,TTL 25]
valueproxy# :: Proxy# a
#

Witness for an unboxed Proxy# value, which has no runtime representation.

valuerightSection :: (a %n -> b %o -> c) -> b %o -> a %n -> c
#
value(*#) :: Int# -> Int# -> Int#
#

Low word of signed integer multiply.

valuetimesInt2# :: Int# -> Int# -> (# Int#, Int#, Int# #)
#

Return a triple (isHighNeeded,high,low) where high and low are respectively the high and low bits of the double-word result. isHighNeeded is a cheap way to test if the high word is a sign-extension of the low word (isHighNeeded = 0#) or not (isHighNeeded = 1#).

valuemulIntMayOflo# :: Int# -> Int# -> Int#
#

Return non-zero if there is any possibility that the upper word of a signed integer multiply might contain useful information. Return zero only if you are completely sure that no overflow can occur. On a 32-bit platform, the recommended implementation is to do a 32 x 32 -> 64 signed multiply, and subtract result[63:32] from (result[31] >>signed 31). If this is zero, meaning that the upper word is merely a sign extension of the lower one, no overflow can occur.

On a 64-bit platform it is not always possible to acquire the top 64 bits of the result. Therefore, a recommended implementation is to take the absolute value of both operands, and return 0 iff bits[63:31] of them are zero, since that means that their magnitudes fit within 31 bits, so the magnitude of the product must fit into 62 bits.

If in doubt, return non-zero, but do make an effort to create the correct answer for small args, since otherwise the performance of (*) :: Integer -> Integer -> Integer will be poor.

valuequotInt# :: Int# -> Int# -> Int#
#

Rounds towards zero. The behavior is undefined if the second argument is zero.

valueremInt# :: Int# -> Int# -> Int#
#

Satisfies (quotInt# x y) *# y +# (remInt# x y) == x. The behavior is undefined if the second argument is zero.

valuenotI# :: Int# -> Int#
#

Bitwise "not", also known as the binary complement.

valuenegateInt# :: Int# -> Int#
#

Unary negation. Since the negative Int# range extends one further than the positive range, negateInt# of the most negative number is an identity operation. This way, negateInt# is always its own inverse.

valueaddIntC# :: Int# -> Int# -> (# Int#, Int# #)
#

Add signed integers reporting overflow. First member of result is the sum truncated to an Int#; second member is zero if the true sum fits in an Int#, nonzero if overflow occurred (the sum is either too large or too small to fit in an Int#).

valuesubIntC# :: Int# -> Int# -> (# Int#, Int# #)
#

Subtract signed integers reporting overflow. First member of result is the difference truncated to an Int#; second member is zero if the true difference fits in an Int#, nonzero if overflow occurred (the difference is either too large or too small to fit in an Int#).

valueint2Float# :: Int# -> Float#
#

Convert an Int# to the corresponding Float# with the same integral value (up to truncation due to floating-point precision). e.g. int2Float# 1# == 1.0#

valueint2Double# :: Int# -> Double#
#

Convert an Int# to the corresponding Double# with the same integral value (up to truncation due to floating-point precision). e.g. int2Double# 1# == 1.0##

valueword2Float# :: Word# -> Float#
#

Convert an Word# to the corresponding Float# with the same integral value (up to truncation due to floating-point precision). e.g. word2Float# 1## == 1.0#

valueword2Double# :: Word# -> Double#
#

Convert an Word# to the corresponding Double# with the same integral value (up to truncation due to floating-point precision). e.g. word2Double# 1## == 1.0##

valueuncheckedIShiftRA# :: Int# -> Int# -> Int#
#

Shift right arithmetic. Result undefined if shift amount is not in the range 0 to word size - 1 inclusive.

valueuncheckedIShiftRL# :: Int# -> Int# -> Int#
#

Shift right logical. Result undefined if shift amount is not in the range 0 to word size - 1 inclusive.

valueaddWordC# :: Word# -> Word# -> (# Word#, Int# #)
#

Add unsigned integers reporting overflow. The first element of the pair is the result. The second element is the carry flag, which is nonzero on overflow. See also plusWord2#.

valuesubWordC# :: Word# -> Word# -> (# Word#, Int# #)
#

Subtract unsigned integers reporting overflow. The first element of the pair is the result. The second element is the carry flag, which is nonzero on overflow.

valueplusWord2# :: Word# -> Word# -> (# Word#, Word# #)
#

Add unsigned integers, with the high part (carry) in the first component of the returned pair and the low part in the second component of the pair. See also addWordC#.

valueuncheckedShiftL# :: Word# -> Int# -> Word#
#

Shift left logical. Result undefined if shift amount is not in the range 0 to word size - 1 inclusive.

valuepopCnt8# :: Word# -> Word#
#

Count the number of set bits in the lower 8 bits of a word.

valuepdep8# :: Word# -> Word# -> Word#
#

Deposit bits to lower 8 bits of a word at locations specified by a mask.

valuepdep16# :: Word# -> Word# -> Word#
#

Deposit bits to lower 16 bits of a word at locations specified by a mask.

valuepdep32# :: Word# -> Word# -> Word#
#

Deposit bits to lower 32 bits of a word at locations specified by a mask.

valuepdep# :: Word# -> Word# -> Word#
#

Deposit bits to a word at locations specified by a mask, aka parallel bit deposit.

Software emulation:

pdep :: Word -> Word -> Word
pdep src mask = go 0 src mask
  where
    go :: Word -> Word -> Word -> Word
    go result _ 0 = result
    go result src mask = go newResult newSrc newMask
      where
        maskCtz   = countTrailingZeros mask
        newResult = if testBit src 0 then setBit result maskCtz else result
        newSrc    = src `shiftR` 1
        newMask   = clearBit mask maskCtz
valuepext8# :: Word# -> Word# -> Word#
#

Extract bits from lower 8 bits of a word at locations specified by a mask.

valuepext16# :: Word# -> Word# -> Word#
#

Extract bits from lower 16 bits of a word at locations specified by a mask.

valuepext32# :: Word# -> Word# -> Word#
#

Extract bits from lower 32 bits of a word at locations specified by a mask.

valuepext# :: Word# -> Word# -> Word#
#

Extract bits from a word at locations specified by a mask, aka parallel bit extract.

Software emulation:

pext :: Word -> Word -> Word
pext src mask = loop 0 0 0
  where
    loop i count result
      | i >= finiteBitSize (0 :: Word)
      = result
      | testBit mask i
      = loop (i + 1) (count + 1) (if testBit src i then setBit result count else result)
      | otherwise
      = loop (i + 1) count result
valueclz8# :: Word# -> Word#
#

Count leading zeros in the lower 8 bits of a word.

valueclz16# :: Word# -> Word#
#

Count leading zeros in the lower 16 bits of a word.

valueclz32# :: Word# -> Word#
#

Count leading zeros in the lower 32 bits of a word.

valuectz8# :: Word# -> Word#
#

Count trailing zeros in the lower 8 bits of a word.

valuectz16# :: Word# -> Word#
#

Count trailing zeros in the lower 16 bits of a word.

valuectz32# :: Word# -> Word#
#

Count trailing zeros in the lower 32 bits of a word.

valuebyteSwap16# :: Word# -> Word#
#

Swap bytes in the lower 16 bits of a word. The higher bytes are undefined.

valuebyteSwap32# :: Word# -> Word#
#

Swap bytes in the lower 32 bits of a word. The higher bytes are undefined.

valuedouble2Int# :: Double# -> Int#
#

Truncates a Double# value to the nearest Int#. Results are undefined if the truncation if truncation yields a value outside the range of Int#.

valuedecodeDouble_2Int# :: Double# -> (# Int#, Word#, Word#, Int# #)
#

Convert to integer. First component of the result is -1 or 1, indicating the sign of the mantissa. The next two are the high and low 32 bits of the mantissa respectively, and the last is the exponent.

valuefloat2Int# :: Float# -> Int#
#

Truncates a Float# value to the nearest Int#. Results are undefined if the truncation if truncation yields a value outside the range of Int#.

valuenewArray# :: Int# -> a -> State# d -> (# State# d, MutableArray# d a #)
#

Create a new mutable array with the specified number of elements, in the specified state thread, with each element containing the specified initial value.

valueindexArray# :: Array# a -> Int# -> (# a #)
#

Read from the specified index of an immutable array. The result is packaged into an unboxed unary tuple; the result itself is not yet evaluated. Pattern matching on the tuple forces the indexing of the array to happen but does not evaluate the element itself. Evaluating the thunk prevents additional thunks from building up on the heap. Avoiding these thunks, in turn, reduces references to the argument array, allowing it to be garbage collected more promptly.

valuecopyArray#
  1. :: Array# a
  2. -> Int#
  3. -> MutableArray# d a
  4. -> Int#
  5. -> Int#
  6. -> State# d
  7. -> State# d
#

Given a source array, an offset into the source array, a destination array, an offset into the destination array, and a number of elements to copy, copy the elements from the source array to the destination array. Both arrays must fully contain the specified ranges, but this is not checked. The two arrays must not be the same array in different states, but this is not checked either.

Given a source array, an offset into the source array, a destination array, an offset into the destination array, and a number of elements to copy, copy the elements from the source array to the destination array. Both arrays must fully contain the specified ranges, but this is not checked. In the case where the source and destination are the same array the source and destination regions may overlap.

valuecloneArray# :: Array# a -> Int# -> Int# -> Array# a
#

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

valuecloneMutableArray#
  1. :: MutableArray# d a
  2. -> Int#
  3. -> Int#
  4. -> State# d
  5. -> (# State# d, MutableArray# d a #)
#

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

valuefreezeArray#
  1. :: MutableArray# d a
  2. -> Int#
  3. -> Int#
  4. -> State# d
  5. -> (# State# d, Array# a #)
#

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

valuethawArray#
  1. :: Array# a
  2. -> Int#
  3. -> Int#
  4. -> State# d
  5. -> (# State# d, MutableArray# d a #)
#

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

valuecasArray#
  1. :: MutableArray# d a
  2. -> Int#
  3. -> a
  4. -> a
  5. -> State# d
  6. -> (# State# d, Int#, a #)
#

Given an array, an offset, the expected old value, and the new value, perform an atomic compare and swap (i.e. write the new value if the current value and the old value are the same pointer). Returns 0 if the swap succeeds and 1 if it fails. Additionally, returns the element at the offset after the operation completes. This means that on a success the new value is returned, and on a failure the actual old value (not the expected one) is returned. Implies a full memory barrier. The use of a pointer equality on a boxed value makes this function harder to use correctly than casIntArray#. All of the difficulties of using reallyUnsafePtrEquality# correctly apply to casArray# as well.

Shrink mutable array to new specified size, in the specified state thread. The new size argument must be less than or equal to the current size as reported by getSizeofSmallMutableArray#.

Assuming the non-profiling RTS, for the copying garbage collector (default) this primitive compiles to an O(1) operation in C--, modifying the array in-place. For the non-moving garbage collector, however, the time is proportional to the number of elements shrinked out. Backends bypassing C-- representation (such as JavaScript) might behave differently.

Return the number of elements in the array. Deprecated, it is unsafe in the presence of shrinkSmallMutableArray# and resizeSmallMutableArray# operations on the same small mutable array.

valueindexSmallArray# :: SmallArray# a -> Int# -> (# a #)
#

Read from specified index of immutable array. Result is packaged into an unboxed singleton; the result itself is not yet evaluated.

Given a source array, an offset into the source array, a destination array, an offset into the destination array, and a number of elements to copy, copy the elements from the source array to the destination array. Both arrays must fully contain the specified ranges, but this is not checked. The two arrays must not be the same array in different states, but this is not checked either.

Given a source array, an offset into the source array, a destination array, an offset into the destination array, and a number of elements to copy, copy the elements from the source array to the destination array. The source and destination arrays can refer to the same array. Both arrays must fully contain the specified ranges, but this is not checked. The regions are allowed to overlap, although this is only possible when the same array is provided as both the source and the destination.

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

valuethawSmallArray#
  1. :: SmallArray# a
  2. -> Int#
  3. -> Int#
  4. -> State# d
  5. -> (# State# d, SmallMutableArray# d a #)
#

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

valuenewByteArray# :: Int# -> State# d -> (# State# d, MutableByteArray# d #)
#

Create a new mutable byte array of specified size (in bytes), in the specified state thread. The size of the memory underlying the array will be rounded up to the platform's word size.

Shrink mutable byte array to new specified size (in bytes), in the specified state thread. The new size argument must be less than or equal to the current size as reported by getSizeofMutableByteArray#.

Assuming the non-profiling RTS, this primitive compiles to an O(1) operation in C--, modifying the array in-place. Backends bypassing C-- representation (such as JavaScript) might behave differently.

Resize mutable byte array to new specified size (in bytes), shrinking or growing it. The returned MutableByteArray# is either the original MutableByteArray# resized in-place or, if not possible, a newly allocated (unpinned) MutableByteArray# (with the original content copied over).

To avoid undefined behaviour, the original MutableByteArray# shall not be accessed anymore after a resizeMutableByteArray# has been performed. Moreover, no reference to the old one should be kept in order to allow garbage collection of the original MutableByteArray# in case a new MutableByteArray# had to be allocated.

Return the size of the array in bytes. Deprecated, it is unsafe in the presence of shrinkMutableByteArray# and resizeMutableByteArray# operations on the same mutable byte array.

compareByteArrays# src1 src1_ofs src2 src2_ofs n compares n bytes starting at offset src1_ofs in the first ByteArray# src1 to the range of n bytes (i.e. same length) starting at offset src2_ofs of the second ByteArray# src2. Both arrays must fully contain the specified ranges, but this is not checked. Returns an Int# less than, equal to, or greater than zero if the range is found, respectively, to be byte-wise lexicographically less than, to match, or be greater than the second range.

copyByteArray# src src_ofs dst dst_ofs len copies the range starting at offset src_ofs of length len from the ByteArray# src to the MutableByteArray# dst starting at offset dst_ofs. Both arrays must fully contain the specified ranges, but this is not checked. The two arrays must not be the same array in different states, but this is not checked either.

copyMutableByteArray# src src_ofs dst dst_ofs len copies the range starting at offset src_ofs of length len from the MutableByteArray# src to the MutableByteArray# dst starting at offset dst_ofs. Both arrays must fully contain the specified ranges, but this is not checked. The regions are allowed to overlap, although this is only possible when the same array is provided as both the source and the destination.

copyMutableByteArrayNonOverlapping# src src_ofs dst dst_ofs len copies the range starting at offset src_ofs of length len from the MutableByteArray# src to the MutableByteArray# dst starting at offset dst_ofs. Both arrays must fully contain the specified ranges, but this is not checked. The regions are not allowed to overlap, but this is also not checked.

Copy a range of the ByteArray# to the memory range starting at the Addr#. The ByteArray# and the memory region at Addr# must fully contain the specified ranges, but this is not checked. The Addr# must not point into the ByteArray# (e.g. if the ByteArray# were pinned), but this is not checked either.

Copy a range of the MutableByteArray# to the memory range starting at the Addr#. The MutableByteArray# and the memory region at Addr# must fully contain the specified ranges, but this is not checked. The Addr# must not point into the MutableByteArray# (e.g. if the MutableByteArray# were pinned), but this is not checked either.

Copy a memory range starting at the Addr# to the specified range in the MutableByteArray#. The memory region at Addr# and the ByteArray# must fully contain the specified ranges, but this is not checked. The Addr# must not point into the MutableByteArray# (e.g. if the MutableByteArray# were pinned), but this is not checked either.

valuecasIntArray#
  1. :: MutableByteArray# d
  2. -> Int#
  3. -> Int#
  4. -> Int#
  5. -> State# d
  6. -> (# State# d, Int# #)
#

Given an array, an offset in machine words, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

valuecasInt8Array#
  1. :: MutableByteArray# d
  2. -> Int#
  3. -> Int8#
  4. -> Int8#
  5. -> State# d
  6. -> (# State# d, Int8# #)
#

Given an array, an offset in bytes, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

Given an array, an offset in 16 bit units, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

Given an array, an offset in 32 bit units, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

Given an array, an offset in 64 bit units, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

valuefetchSubIntArray#
  1. :: MutableByteArray# d
  2. -> Int#
  3. -> Int#
  4. -> State# d
  5. -> (# State# d, Int# #)
#

Given an array, and offset in machine words, and a value to subtract, atomically subtract the value from the element. Returns the value of the element before the operation. Implies a full memory barrier.

valueminusAddr# :: Addr# -> Addr# -> Int#
#

Result is meaningless if two Addr#s are so far apart that their difference doesn't fit in an Int#.

valueremAddr# :: Addr# -> Int# -> Int#
#

Return the remainder when the Addr# arg, treated like an Int#, is divided by the Int# arg.

Read a 32-bit character; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

valueindexIntOffAddr# :: Addr# -> Int# -> Int#
#

Read a word-sized integer; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

valueindexWordOffAddr# :: Addr# -> Int# -> Word#
#

Read a word-sized unsigned integer; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

valueindexAddrOffAddr# :: Addr# -> Int# -> Addr#
#

Read a machine address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Read a single-precision floating-point value; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Read a double-precision floating-point value; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Read a 16-bit signed integer; offset in 2-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Read a 16-bit unsigned integer; offset in 2-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Read a 32-bit signed integer; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Read a 32-bit unsigned integer; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Read a 64-bit signed integer; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Read a 64-bit unsigned integer; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

valuereadIntOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Int# #)
#

Read a word-sized integer; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

valuereadWordOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Word# #)
#

Read a word-sized unsigned integer; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

valuereadFloatOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Float# #)
#

Read a single-precision floating-point value; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

valueatomicCasAddrAddr#
  1. :: Addr#
  2. -> Addr#
  3. -> Addr#
  4. -> State# d
  5. -> (# State# d, Addr# #)
#

Compare and swap on a word-sized memory location.

Use as: s -> atomicCasAddrAddr# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

valueatomicCasWordAddr#
  1. :: Addr#
  2. -> Word#
  3. -> Word#
  4. -> State# d
  5. -> (# State# d, Word# #)
#

Compare and swap on a word-sized and aligned memory location.

Use as: s -> atomicCasWordAddr# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

valueatomicCasWord8Addr#
  1. :: Addr#
  2. -> Word8#
  3. -> Word8#
  4. -> State# d
  5. -> (# State# d, Word8# #)
#

Compare and swap on a 8 bit-sized and aligned memory location.

Use as: s -> atomicCasWordAddr8# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

Compare and swap on a 16 bit-sized and aligned memory location.

Use as: s -> atomicCasWordAddr16# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

Compare and swap on a 32 bit-sized and aligned memory location.

Use as: s -> atomicCasWordAddr32# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

Compare and swap on a 64 bit-sized and aligned memory location.

Use as: s -> atomicCasWordAddr64# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

valuefetchAddWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #)
#

Given an address, and a value to add, atomically add the value to the element. Returns the value of the element before the operation. Implies a full memory barrier.

valuefetchSubWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #)
#

Given an address, and a value to subtract, atomically subtract the value from the element. Returns the value of the element before the operation. Implies a full memory barrier.

valuefetchAndWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #)
#

Given an address, and a value to AND, atomically AND the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

valuefetchNandWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #)
#

Given an address, and a value to NAND, atomically NAND the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

valuefetchOrWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #)
#

Given an address, and a value to OR, atomically OR the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

valuefetchXorWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #)
#

Given an address, and a value to XOR, atomically XOR the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

valueatomicModifyMutVar2#
  1. :: MutVar# d a
  2. -> a -> c
  3. -> State# d
  4. -> (# State# d, a, c #)
#

Modify the contents of a MutVar#, returning the previous contents x :: a and the result of applying the given function to the previous contents f x :: c.

The data type c (not a newtype!) must be a record whose first field is of lifted type a :: Type and is not unpacked. For example, product types c ~ Solo a or c ~ (a, b) work well. If the record type is both monomorphic and strict in its first field, it's recommended to mark the latter {-# NOUNPACK #-} explicitly.

Under the hood atomicModifyMutVar2# atomically replaces a pointer to an old x :: a with a pointer to a selector thunk fst r, where fst is a selector for the first field of the record and r is a function application thunk r = f x.

atomicModifyIORef2Native from atomic-modify-general package makes an effort to reflect restrictions on c faithfully, providing a well-typed high-level wrapper.

valueatomicModifyMutVar_#
  1. :: MutVar# d a
  2. -> a -> a
  3. -> State# d
  4. -> (# State# d, a, a #)
#

Modify the contents of a MutVar#, returning the previous contents and the result of applying the given function to the previous contents.

valuecasMutVar# :: MutVar# d a -> a -> a -> State# d -> (# State# d, Int#, a #)
#

Compare-and-swap: perform a pointer equality test between the first value passed to this function and the value stored inside the MutVar#. If the pointers are equal, replace the stored value with the second value passed to this function, otherwise do nothing. Returns the final value stored inside the MutVar#. The Int# indicates whether a swap took place, with 1# meaning that we didn't swap, and 0# that we did. Implies a full memory barrier. Because the comparison is done on the level of pointers, all of the difficulties of using reallyUnsafePtrEquality# correctly apply to casMutVar# as well.

maskAsyncExceptions# k s evaluates k s such that asynchronous exceptions are deferred until after evaluation has finished.

Note that the result type here isn't quite as unrestricted as the polymorphic type might suggest; see the section "RuntimeRep polymorphism in continuation-style primops" for details.

maskUninterruptible# k s evaluates k s such that asynchronous exceptions are deferred until after evaluation has finished.

Note that the result type here isn't quite as unrestricted as the polymorphic type might suggest; see the section "RuntimeRep polymorphism in continuation-style primops" for details.

valuereadTVar# :: TVar# d a -> State# d -> (# State# d, a #)
#

Read contents of TVar# inside an STM transaction, i.e. within a call to atomically#. Does not force evaluation of the result.

valuereadTVarIO# :: TVar# d a -> State# d -> (# State# d, a #)
#

Read contents of TVar# outside an STM transaction. Does not force evaluation of the result.

valuetakeMVar# :: MVar# d a -> State# d -> (# State# d, a #)
#

If MVar# is empty, block until it becomes full. Then remove and return its contents, and set it empty.

valuetryTakeMVar# :: MVar# d a -> State# d -> (# State# d, Int#, a #)
#

If MVar# is empty, immediately return with integer 0 and value undefined. Otherwise, return with integer 1 and contents of MVar#, and set MVar# empty.

valueputMVar# :: MVar# d a -> a -> State# d -> State# d
#

If MVar# is full, block until it becomes empty. Then store value arg as its new contents.

valuetryPutMVar# :: MVar# d a -> a -> State# d -> (# State# d, Int# #)
#

If MVar# is full, immediately return with integer 0. Otherwise, store value arg as MVar#'s new contents, and return with integer 1.

valuereadMVar# :: MVar# d a -> State# d -> (# State# d, a #)
#

If MVar# is empty, block until it becomes full. Then read its contents without modifying the MVar, without possibility of intervention from other threads.

valuetryReadMVar# :: MVar# d a -> State# d -> (# State# d, Int#, a #)
#

If MVar# is empty, immediately return with integer 0 and value undefined. Otherwise, return with integer 1 and contents of MVar#.

valuereadIOPort# :: IOPort# d a -> State# d -> (# State# d, a #)
#

If IOPort# is empty, block until it becomes full. Then remove and return its contents, and set it empty. Throws an IOPortException if another thread is already waiting to read this IOPort#.

valuewriteIOPort# :: IOPort# d a -> a -> State# d -> (# State# d, Int# #)
#

If IOPort# is full, immediately return with integer 0, throwing an IOPortException. Otherwise, store value arg as IOPort#'s new contents, and return with integer 1.

Get the status of the given thread. Result is (ThreadStatus, Capability, Locked) where ThreadStatus is one of the status constants defined in rts/Constants.h, Capability is the number of the capability which currently owns the thread, and Locked is a boolean indicating whether the thread is bound to that capability.

Returns an array of the threads started by the program. Note that this threads which have finished execution may or may not be present in this list, depending upon whether they have been collected by the garbage collector.

valuemkWeak#
  1. :: a
  2. -> b
  3. -> State# RealWorld -> (# State# RealWorld, c #)
  4. -> State# RealWorld
  5. -> (# State# RealWorld, Weak# b #)
#

mkWeak# k v finalizer s creates a weak reference to value k, with an associated reference to some value v. If k is still alive then v can be retrieved using deRefWeak#. Note that the type of k must be represented by a pointer (i.e. of kind TYPE 'LiftedRep or TYPE 'UnliftedRep@).

addCFinalizerToWeak# fptr ptr flag eptr w attaches a C function pointer fptr to a weak pointer w as a finalizer. If flag is zero, fptr will be called with one argument, ptr. Otherwise, it will be called with two arguments, eptr and ptr. addCFinalizerToWeak# returns 1 on success, or 0 if w is already dead.

Finalize a weak pointer. The return value is an unboxed tuple containing the new state of the world and an "unboxed Maybe", represented by an Int# and a (possibly invalid) finalization action. An Int# of 1 indicates that the finalizer is valid. The return value b from the finalizer should be ignored.

Create a new CNF with a single compact block. The argument is the capacity of the compact block (in bytes, not words). The capacity is rounded up to a multiple of the allocator block size and is capped to one mega block.

Attempt to allocate a compact block with the capacity (in bytes) given by the first argument. The Addr# is a pointer to previous compact block of the CNF or nullAddr# to create a new CNF with a single compact block.

The resulting block is not known to the GC until compactFixupPointers# is called on it, and care must be taken so that the address does not escape or memory will be leaked.

Given the pointer to the first block of a CNF and the address of the root object in the old address space, fix up the internal pointers inside the CNF to account for a different position in memory than when it was serialized. This method must be called exactly once after importing a serialized CNF. It returns the new CNF and the new adjusted root address.

valuecompactAdd#
  1. :: Compact#
  2. -> a
  3. -> State# RealWorld
  4. -> (# State# RealWorld, a #)
#

Recursively add a closure and its transitive closure to a Compact# (a CNF), evaluating any unevaluated components at the same time. Note: compactAdd# is not thread-safe, so only one thread may call compactAdd# with a particular Compact# at any given time. The primop does not enforce any mutual exclusion; the caller is expected to arrange this.

valuekeepAlive# :: a -> State# d -> (State# d -> b) -> b
#

keepAlive# x s k keeps the value x alive during the execution of the computation k.

Note that the result type here isn't quite as unrestricted as the polymorphic type might suggest; see the section "RuntimeRep polymorphism in continuation-style primops" for details.

valueaddrToAny# :: Addr# -> (# a #)
#

Convert an Addr# to a followable Any type.

valueanyToAddr# :: a -> State# RealWorld -> (# State# RealWorld, Addr# #)
#

Retrieve the address of any Haskell value. This is essentially an unsafeCoerce#, but if implemented as such the core lint pass complains and fails to compile. As a primop, it is opaque to core/stg, and only appears in cmm (where the copy propagation pass will get rid of it). Note that "a" must be a value, not a thunk! It's too late for strictness analysis to enforce this, so you're on your own to guarantee this. Also note that Addr# is not a GC pointer - up to you to guarantee that it does not become a dangling pointer immediately after you get it.

valuemkApUpd0# :: BCO -> (# a #)
#

Wrap a BCO in a AP_UPD thunk which will be updated with the value of the BCO when evaluated.

valuenewBCO#
  1. :: ByteArray#
  2. -> ByteArray#
  3. -> Array# a
  4. -> Int#
  5. -> ByteArray#
  6. -> State# d
  7. -> (# State# d, BCO #)
#

newBCO# instrs lits ptrs arity bitmap creates a new bytecode object. The resulting object encodes a function of the given arity with the instructions encoded in instrs, and a static reference table usage bitmap given by bitmap.

valueunpackClosure# :: a -> (# Addr#, ByteArray#, Array# b #)
#

unpackClosure# closure copies the closure and pointers in the payload of the given closure into two new arrays, and returns a pointer to the first word of the closure's info table, a non-pointer array for the raw bytes of the closure, and a pointer array for the pointers in the payload.

valueclosureSize# :: a -> Int#
#

closureSize# closure returns the size of the given closure in machine words.

valuegetCurrentCCS# :: a -> State# d -> (# State# d, Addr# #)
#

Returns the current CostCentreStack (value is NULL if not profiling). Takes a dummy argument which can be used to avoid the call to getCurrentCCS# being floated out by the simplifier, which would result in an uninformative stack (CAF).

valueclearCCS#
  1. :: State# d -> (# State# d, a #)
  2. -> State# d
  3. -> (# State# d, a #)
#

Run the supplied IO action with an empty CCS. For example, this is used by the interpreter to run an interpreted computation without the call stack showing that it was invoked from GHC.

valuetraceEvent# :: Addr# -> State# d -> State# d
#

Emits an event via the RTS tracing framework. The contents of the event is the zero-terminated byte string passed as the first argument. The event will be emitted either to the .eventlog file, or to stderr, depending on the runtime RTS flags.

valuetraceBinaryEvent# :: Addr# -> Int# -> State# d -> State# d
#

Emits an event via the RTS tracing framework. The contents of the event is the binary object passed as the first argument with the given length passed as the second argument. The event will be emitted to the .eventlog file.

valuetraceMarker# :: Addr# -> State# d -> State# d
#

Emits a marker event via the RTS tracing framework. The contents of the event is the zero-terminated byte string passed as the first argument. The event will be emitted either to the .eventlog file, or to stderr, depending on the runtime RTS flags.

Pack the elements of an unboxed tuple into a vector.

Pack the elements of an unboxed tuple into a vector.

Unpack the elements of a vector into an unboxed tuple. #

Unpack the elements of a vector into an unboxed tuple. #

valuereallyUnsafePtrEquality :: a -> a -> Int#
#

Compare the underlying pointers of two values for equality.

Returns 1 if the pointers are equal and 0 otherwise.

The two values must be of the same type, of kind Type. See also reallyUnsafePtrEquality#, which doesn't have such restrictions.

valueunsafePtrEquality# :: a -> b -> Int#
#

Compare the underlying pointers of two unlifted values for equality.

This is less dangerous than reallyUnsafePtrEquality, since the arguments are guaranteed to be evaluated. This means there is no risk of accidentally comparing a thunk. It's however still more dangerous than e.g. sameArray#.

valueabsentErr :: a
#

Used for compiler-generated error message; encoding saves bytes of string junk.

valueundefined :: HasCallStack => a
#

A special case of error. It is expected that compilers will recognize this and insert error messages which are more appropriate to the context in which undefined appears.

datadata Maybe a
#

The Maybe type encapsulates an optional value. A value of type Maybe a either contains a value of type a (represented as Just a), or it is empty (represented as Nothing). Using Maybe is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error.

The Maybe type is also a monad. It is a simple kind of error monad, where all errors are represented by Nothing. A richer error monad can be built using the Either type.

Constructors

Instances30Monad, Functor, MonadFix, MonadFail, Applicative, Foldable, …

Equality and ordering

3 declarations
classclass IP (x :: Symbol) a | x -> a where
#

The syntax ?x :: a is desugared into IP "x" a IP is declared very early, so that libraries can take advantage of the implicit-call-stack feature

Methods

classclass Eq a where
#

The Eq class defines equality (==) and inequality (/=). All the basic datatypes exported by the Prelude are instances of Eq, and Eq may be derived for any datatype whose constituents are also instances of Eq.

The Haskell Report defines no laws for Eq. However, instances are encouraged to follow these properties:

Reflexivity

x == x

=

True

Symmetry

x == y

=

y == x

Transitivity

if

x == y && y == z

=

True

, then

x == z

=

True

Extensionality

if

x == y

=

True

and

f

is a function whose return type is an instance of

Eq

, then

f x == f y

=

True

Negation

x /= y

=

not (x == y)

Methods

Instances226Eq, …
  • Eq ByteArrayDefined in base-4.20.2.0 · Data.Array.Byte
  • Eq TimeoutDefined in base-4.20.2.0 · System.Timeout
  • Eq BigNatDefined in ghc-bignum-1.3 · GHC.Num.BigNat
  • Eq IntegerDefined in ghc-bignum-1.3 · GHC.Num.Integer
  • Eq NaturalDefined in ghc-bignum-1.3 · GHC.Num.Natural
  • Eq VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Eq ByteOrderDefined in ghc-internal-9.1003.0 · GHC.Internal.ByteOrder
  • Eq ClosureTypeDefined in ghc-internal-9.1003.0 · GHC.Internal.ClosureTypes
  • Eq BlockReasonDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Eq ThreadIdDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Eq ThreadStatusDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Eq ConstrDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data

    Equality of constructors

  • Eq ConstrRepDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Eq DataRepDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Eq FixityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Eq AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Eq AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Eq SomeTypeRepDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.Internal
  • Eq UniqueDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Unique
  • Eq VersionDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Version
  • Eq ControlMessageDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Control
  • Eq EPollFdDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.EPoll
  • Eq EventTypeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.EPoll
  • Eq EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types
  • Eq EventLifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types
  • Eq LifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types
  • Eq FdKeyDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Manager
  • Eq StateDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Manager
  • Eq EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Poll
  • Eq TimeoutKeyDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.TimeOut
  • Eq StateDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.TimerManager
  • Eq UniqueDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Unique
  • Eq ErrorCallDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception
  • Eq ArithExceptionDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception.Type
  • Eq SpecConstrAnnotationDefined in ghc-internal-9.1003.0 · GHC.Internal.Exts
  • Eq FingerprintDefined in ghc-internal-9.1003.0 · GHC.Internal.Fingerprint.Type
  • Eq ErrnoDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Error
  • Eq CBoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CClockDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CLLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CPtrdiffDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CSCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CSUSecondsDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CSigAtomicDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CTimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CUCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CUIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CUIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CUIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CULLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CULongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CUSecondsDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CUShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq CWcharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Eq IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Ptr
  • Eq WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Ptr
  • Eq AssociativityDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq DecidedStrictnessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq FixityDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq SourceStrictnessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq SourceUnpackednessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq MaskingStateDefined in ghc-internal-9.1003.0 · GHC.Internal.IO
  • Eq BufferStateDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Buffer
  • Eq IODeviceTypeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Device
  • Eq SeekModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Device
  • Eq CodingProgressDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Encoding.Types
  • Eq ArrayExceptionDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception
  • Eq AsyncExceptionDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception
  • Eq ExitCodeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception
  • Eq IOErrorTypeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception
  • Eq IOExceptionDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception
  • Eq HandlePosnDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle
  • Eq BufferModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Types
  • Eq HandleDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Types
  • Eq NewlineDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Types
  • Eq NewlineModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Types
  • Eq IOModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.IOMode
  • Eq InfoProvDefined in ghc-internal-9.1003.0 · GHC.Internal.InfoProv.Types
  • Eq Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Eq Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Eq Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Eq Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Eq IoSubSystemDefined in ghc-internal-9.1003.0 · GHC.Internal.RTS.Flags
  • Eq StackEntryDefined in ghc-internal-9.1003.0 · GHC.Internal.Stack.CloneStack
  • Eq SrcLocDefined in ghc-internal-9.1003.0 · GHC.Internal.Stack.Types
  • Eq CBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CBlkSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CCcDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CClockIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CDevDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CFsBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CFsFilCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CGidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CInoDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CKeyDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CModeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CNfdsDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CNlinkDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq COffDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CPidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CRLimDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CSocklenDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CSpeedDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CSsizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CTcflagDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CTimerDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq CUidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq LexemeDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.Read.Lex
  • Eq NumberDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.Read.Lex
  • Eq SomeCharDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Eq SomeSymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Eq SomeNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Eq GeneralCategoryDefined in ghc-internal-9.1003.0 · GHC.Internal.Unicode
  • Eq Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Eq Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Eq Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Eq Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Eq BoolDefined in ghc-prim-0.12.0 · GHC.Classes
  • Eq CharDefined in ghc-prim-0.12.0 · GHC.Classes
  • Eq DoubleDefined in ghc-prim-0.12.0 · GHC.Classes

    Note that due to the presence of NaN, Double's Eq instance does not satisfy reflexivity.

    Example1 expression
    0/0 == (0/0 :: Double)False

    Also note that Double's Eq instance does not satisfy substitutivity:

    Example2 expressions
    0 == (-0 :: Double)Truerecip 0 == recip (-0 :: Double)False
  • Eq FloatDefined in ghc-prim-0.12.0 · GHC.Classes

    Note that due to the presence of NaN, Float's Eq instance does not satisfy reflexivity.

    Example1 expression
    0/0 == (0/0 :: Float)False

    Also note that Float's Eq instance does not satisfy extensionality:

    Example2 expressions
    0 == (-0 :: Float)Truerecip 0 == recip (-0 :: Float)False
  • Eq IntDefined in ghc-prim-0.12.0 · GHC.Classes
  • Eq ModuleDefined in ghc-prim-0.12.0 · GHC.Classes
  • Eq OrderingDefined in ghc-prim-0.12.0 · GHC.Classes
  • Eq TrNameDefined in ghc-prim-0.12.0 · GHC.Classes
  • Eq TyConDefined in ghc-prim-0.12.0 · GHC.Classes
  • Eq WordDefined in ghc-prim-0.12.0 · GHC.Classes
  • Eq ()Defined in ghc-prim-0.12.0 · GHC.Classes
  • Eq (Chan a)Defined in base-4.20.2.0 · Control.Concurrent.Chan
  • Eq (MutableByteArray s)Defined in base-4.20.2.0 · Data.Array.Byte
  • Eq (TVar a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Eq (ConstPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.ConstPtr
  • Eq (ForeignPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.ForeignPtr
  • Eq (IOPort a)Defined in ghc-internal-9.1003.0 · GHC.Internal.IOPort
  • Eq (IORef a)Defined in ghc-internal-9.1003.0 · GHC.Internal.IORef

    Pointer equality.

  • Eq (MVar a)Defined in ghc-internal-9.1003.0 · GHC.Internal.MVar

    Compares the underlying pointers.

  • Eq (FunPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ptr
  • Eq (Ptr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ptr
  • Eq (StablePtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Stable
  • Eq (StableName a)Defined in ghc-internal-9.1003.0 · GHC.Internal.StableName
  • Eq (SChar c)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Eq (SSymbol s)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Eq (SNat n)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Eq a => Eq (Complex a)Defined in base-4.20.2.0 · Data.Complex
  • Eq a => Eq (First a)Defined in base-4.20.2.0 · Data.Semigroup
  • Eq a => Eq (Last a)Defined in base-4.20.2.0 · Data.Semigroup
  • Eq a => Eq (Max a)Defined in base-4.20.2.0 · Data.Semigroup
  • Eq a => Eq (Min a)Defined in base-4.20.2.0 · Data.Semigroup
  • Eq a => Eq (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Eq a => Eq (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Eq a => Eq (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Eq a => Eq (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Eq a => Eq (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Eq a => Eq (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identity
  • Eq a => Eq (First a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Eq a => Eq (Last a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Eq a => Eq (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Ord
  • Eq a => Eq (Dual a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Eq a => Eq (Product a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Eq a => Eq (Sum a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Eq a => Eq (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipList
  • Eq a => Eq (Maybe a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Maybe
  • Eq a => Eq (Ratio a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Eq a => Eq (a)Defined in ghc-prim-0.12.0 · GHC.Classes
  • Eq a => Eq [a]Defined in ghc-prim-0.12.0 · GHC.Classes
  • Eq m => Eq (WrappedMonoid m)Defined in base-4.20.2.0 · Data.Semigroup
  • Eq p => Eq (Par1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (Fixed a)Defined in base-4.20.2.0 · Data.Fixed
  • Eq (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Eq (TypeRep a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.Internal
  • Eq (U1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (V1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (IOArray i e)Defined in ghc-internal-9.1003.0 · GHC.Internal.IOArray
  • Eq (STRef s a)Defined in ghc-internal-9.1003.0 · GHC.Internal.STRef

    Pointer equality.

  • Eq a => Eq (Arg a b)Defined in base-4.20.2.0 · Data.Semigroup
  • (Ix i, Eq e) => Eq (Array i e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Arr
  • (Eq a, Eq b) => Eq (Either a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Either
  • (Eq a, Eq b) => Eq (a, b)Defined in ghc-prim-0.12.0 · GHC.Classes
  • Eq (STArray s i e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Arr
  • Eq (Coercion a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Coercion
  • Eq (OrderingI a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Ord
  • Eq (URec Char p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (URec Word p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (URec (Ptr ()) p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • Eq (f a) => Eq (Ap f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Eq (f a) => Eq (Alt f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Eq (f p) => Eq (Rec1 f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq a => Eq (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const
  • (Generic1 f, Eq (Rep1 f a)) => Eq (Generically1 f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Eq a, Eq b, Eq c) => Eq (a, b, c)Defined in ghc-prim-0.12.0 · GHC.Classes
  • Eq (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • Eq c => Eq (K1 i c p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Eq (f a), Eq (g a)) => Eq (Product f g a)Defined in base-4.20.2.0 · Data.Functor.Product
  • (Eq (f a), Eq (g a)) => Eq (Sum f g a)Defined in base-4.20.2.0 · Data.Functor.Sum
  • (Eq (f p), Eq (g p)) => Eq ((:*:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Eq (f p), Eq (g p)) => Eq ((:+:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d)Defined in ghc-prim-0.12.0 · GHC.Classes
  • Eq (f (g a)) => Eq (Compose f g a)Defined in base-4.20.2.0 · Data.Functor.Compose
  • Eq (f (g p)) => Eq ((:.:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Eq (f p) => Eq (M1 i c f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)Defined in ghc-prim-0.12.0 · GHC.Classes
classclass Eq a => Ord a where
#

The Ord class is used for totally ordered datatypes.

Instances of Ord can be derived for any user-defined datatype whose constituent types are in Ord. The declared order of the constructors in the data declaration determines the ordering in derived Ord instances. The Ordering datatype allows a single comparison to determine the precise ordering of two objects.

Ord, as defined by the Haskell report, implements a total order and has the following properties:

Comparability

x <= y || y <= x

=

True

Transitivity

if

x <= y && y <= z

=

True

, then

x <= z

=

True

Reflexivity

x <= x

=

True

Antisymmetry

if

x <= y && y <= x

=

True

, then

x == y

=

True

The following operator interactions are expected to hold:

  1. x >= y = y <= x

  2. x < y = x <= y && x /= y

  3. x > y = y < x

  4. x < y = compare x y == LT

  5. x > y = compare x y == GT

  6. x == y = compare x y == EQ

  7. min x y == if x <= y then x else y = True

  8. max x y == if x >= y then x else y = True

Note that (7.) and (8.) do not require min and max to return either of their arguments. The result is merely required to equal one of the arguments in terms of (==).

Minimal complete definition: either compare or <=. Using compare can be more efficient for complex types.

Methods

Instances176Ord, …
  • Ord ByteArrayDefined in base-4.20.2.0 · Data.Array.Byte

    Non-lexicographic ordering. This compares the lengths of the byte arrays first and uses a lexicographic ordering if the lengths are equal. Subject to change between major versions.

  • Ord BigNatDefined in ghc-bignum-1.3 · GHC.Num.BigNat
  • Ord IntegerDefined in ghc-bignum-1.3 · GHC.Num.Integer
  • Ord NaturalDefined in ghc-bignum-1.3 · GHC.Num.Natural
  • Ord VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Ord ByteOrderDefined in ghc-internal-9.1003.0 · GHC.Internal.ByteOrder
  • Ord ClosureTypeDefined in ghc-internal-9.1003.0 · GHC.Internal.ClosureTypes
  • Ord BlockReasonDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Ord ThreadIdDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Ord ThreadStatusDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Ord AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Ord AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Ord SomeTypeRepDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.Internal
  • Ord UniqueDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Unique
  • Ord VersionDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Version
  • Ord TimeoutKeyDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.TimeOut
  • Ord UniqueDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Unique
  • Ord ErrorCallDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception
  • Ord ArithExceptionDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception.Type
  • Ord FingerprintDefined in ghc-internal-9.1003.0 · GHC.Internal.Fingerprint.Type
  • Ord CBoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CClockDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CLLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CPtrdiffDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CSCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CSUSecondsDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CSigAtomicDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CTimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CUCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CUIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CUIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CUIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CULLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CULongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CUSecondsDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CUShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord CWcharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Ord IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Ptr
  • Ord WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Ptr
  • Ord AssociativityDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord DecidedStrictnessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord FixityDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord SourceStrictnessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord SourceUnpackednessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord SeekModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Device
  • Ord ArrayExceptionDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception
  • Ord AsyncExceptionDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception
  • Ord ExitCodeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception
  • Ord BufferModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Types
  • Ord NewlineDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Types
  • Ord NewlineModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Types
  • Ord IOModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.IOMode
  • Ord Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Ord Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Ord Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Ord Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Ord CBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CBlkSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CCcDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CClockIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CDevDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CFsBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CFsFilCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CGidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CInoDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CKeyDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CModeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CNfdsDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CNlinkDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord COffDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CPidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CRLimDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CSocklenDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CSpeedDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CSsizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CTcflagDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CTimerDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord CUidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord SomeCharDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Ord SomeSymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Ord SomeNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Ord GeneralCategoryDefined in ghc-internal-9.1003.0 · GHC.Internal.Unicode
  • Ord Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ord Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ord Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ord Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ord BoolDefined in ghc-prim-0.12.0 · GHC.Classes
  • Ord CharDefined in ghc-prim-0.12.0 · GHC.Classes
  • Ord DoubleDefined in ghc-prim-0.12.0 · GHC.Classes

    IEEE 754 Double-precision type includes not only numbers, but also positive and negative infinities and a special element called NaN (which can be quiet or signal).

    IEEE 754-2008, section 5.11 requires that if at least one of arguments of <=, <, >, >= is NaN then the result of the comparison is False, and instance Ord Double complies with this requirement. This violates the reflexivity: both NaN <= NaN and NaN >= NaN are False.

    IEEE 754-2008, section 5.10 defines totalOrder predicate. Unfortunately, compare on Doubles violates the IEEE standard and does not define a total order. More specifically, both compare NaN x and compare x NaN always return GT.

    Thus, users must be extremely cautious when using instance Ord Double. For instance, one should avoid ordered containers with keys represented by Double, because data loss and corruption may happen. An IEEE-compliant compare is available in fp-ieee package as TotallyOrdered newtype.

    Moving further, the behaviour of min and max with regards to NaN is also non-compliant. IEEE 754-2008, section 5.3.1 defines that quiet NaN should be treated as a missing data by minNum and maxNum functions, for example, minNum(NaN, 1) = minNum(1, NaN) = 1. Some languages such as Java deviate from the standard implementing minNum(NaN, 1) = minNum(1, NaN) = NaN. However, min / max in base are even worse: min NaN 1 is 1, but min 1 NaN is NaN.

    IEEE 754-2008 compliant min / max can be found in ieee754 package under minNum / maxNum names. Implementations compliant with minimumNumber / maximumNumber from a newer IEEE 754-2019, section 9.6 are available from fp-ieee package.

  • Ord FloatDefined in ghc-prim-0.12.0 · GHC.Classes

    See instance Ord Double for discussion of deviations from IEEE 754 standard.

  • Ord IntDefined in ghc-prim-0.12.0 · GHC.Classes
  • Ord OrderingDefined in ghc-prim-0.12.0 · GHC.Classes
  • Ord TyConDefined in ghc-prim-0.12.0 · GHC.Classes
  • Ord WordDefined in ghc-prim-0.12.0 · GHC.Classes
  • Ord ()Defined in ghc-prim-0.12.0 · GHC.Classes
  • Integral a => Ord (Ratio a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Ord (ConstPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.ConstPtr
  • Ord (ForeignPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.ForeignPtr
  • Ord (FunPtr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ptr
  • Ord (Ptr a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Ptr
  • Ord (SChar c)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Ord (SSymbol s)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Ord (SNat n)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Ord a => Ord (First a)Defined in base-4.20.2.0 · Data.Semigroup
  • Ord a => Ord (Last a)Defined in base-4.20.2.0 · Data.Semigroup
  • Ord a => Ord (Max a)Defined in base-4.20.2.0 · Data.Semigroup
  • Ord a => Ord (Min a)Defined in base-4.20.2.0 · Data.Semigroup
  • Ord a => Ord (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Ord a => Ord (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identity
  • Ord a => Ord (First a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Ord a => Ord (Last a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Ord a => Ord (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Ord
  • Ord a => Ord (Dual a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Ord a => Ord (Product a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Ord a => Ord (Sum a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Ord a => Ord (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipList
  • Ord a => Ord (Maybe a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Maybe
  • Ord a => Ord (a)Defined in ghc-prim-0.12.0 · GHC.Classes
  • Ord a => Ord [a]Defined in ghc-prim-0.12.0 · GHC.Classes
  • Ord m => Ord (WrappedMonoid m)Defined in base-4.20.2.0 · Data.Semigroup
  • Ord p => Ord (Par1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (Fixed a)Defined in base-4.20.2.0 · Data.Fixed
  • Ord (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Ord (TypeRep a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.Internal
  • Ord (U1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (V1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord a => Ord (Arg a b)Defined in base-4.20.2.0 · Data.Semigroup
  • (Ix i, Ord e) => Ord (Array i e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Arr
  • (Ord a, Ord b) => Ord (Either a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Either
  • (Ord a, Ord b) => Ord (a, b)Defined in ghc-prim-0.12.0 · GHC.Classes
  • Ord (Coercion a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Coercion
  • Ord (URec Char p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (URec Double p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (URec Float p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (URec Int p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (URec Word p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (URec (Ptr ()) p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • Ord (f a) => Ord (Ap f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Ord (f a) => Ord (Alt f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Ord (f p) => Ord (Rec1 f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord a => Ord (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const
  • (Generic1 f, Ord (Rep1 f a)) => Ord (Generically1 f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Ord a, Ord b, Ord c) => Ord (a, b, c)Defined in ghc-prim-0.12.0 · GHC.Classes
  • Ord (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • Ord c => Ord (K1 i c p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Ord (f a), Ord (g a)) => Ord (Product f g a)Defined in base-4.20.2.0 · Data.Functor.Product
  • (Ord (f a), Ord (g a)) => Ord (Sum f g a)Defined in base-4.20.2.0 · Data.Functor.Sum
  • (Ord (f p), Ord (g p)) => Ord ((:*:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Ord (f p), Ord (g p)) => Ord ((:+:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d)Defined in ghc-prim-0.12.0 · GHC.Classes
  • Ord (f (g a)) => Ord (Compose f g a)Defined in base-4.20.2.0 · Data.Functor.Compose
  • Ord (f (g p)) => Ord ((:.:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Ord (f p) => Ord (M1 i c f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) => Ord (a, b, c, d, e, f)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g) => Ord (a, b, c, d, e, f, g)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h) => Ord (a, b, c, d, e, f, g, h)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i) => Ord (a, b, c, d, e, f, g, h, i)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j) => Ord (a, b, c, d, e, f, g, h, i, j)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k) => Ord (a, b, c, d, e, f, g, h, i, j, k)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l) => Ord (a, b, c, d, e, f, g, h, i, j, k, l)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n)Defined in ghc-prim-0.12.0 · GHC.Classes
  • (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)Defined in ghc-prim-0.12.0 · GHC.Classes

Monomorphic equality operators

C Strings

8 declarations
valuecstringLength# :: Addr# -> Int#
#

Compute the length of a NUL-terminated string. This address must refer to immutable memory. GHC includes a built-in rule for constant folding when the argument is a statically-known literal. That is, a core-to-core pass reduces the expression cstringLength# "hello"# to the constant 5#.

Magic combinators

7 declarations
valueinline :: a -> a
#

The call inline f arranges that f is inlined, regardless of its size. More precisely, the call inline f rewrites to the right-hand side of f's definition. This allows the programmer to control inlining from a particular call site rather than the definition site of the function (c.f. INLINE pragmas).

This inlining occurs regardless of the argument to the call or the size of f's definition; it is unconditional. The main caveat is that f's definition must be visible to the compiler; it is therefore recommended to mark the function with an INLINABLE pragma at its definition so that GHC guarantees to record its unfolding regardless of size.

If no inlining takes place, the inline function expands to the identity function in Phase zero, so its use imposes no overhead.

valuenoinline :: a -> a
#

The call noinline f arranges that f will not be inlined. It is removed during CorePrep so that its use imposes no overhead (besides the fact that it blocks inlining.)

valuelazy :: a -> a
#

The lazy function restrains strictness analysis a little. The call lazy e means the same as e, but lazy has a magical property so far as strictness analysis is concerned: it is lazy in its first argument, even though its semantics is strict. After strictness analysis has run, calls to lazy are inlined to be the identity function.

This behaviour is occasionally useful when controlling evaluation order. Notably, lazy is used in the library definition of Control.Parallel.par:

par :: a -> b -> b
par x y = case (par# x) of _ -> lazy y

If lazy were not lazy, Control.Parallel.par would look strict in y which would defeat the whole purpose of Control.Parallel.par.

valueoneShot :: (a -> b) -> a -> b
#

The oneShot function can be used to give a hint to the compiler that its argument will be called at most once, which may (or may not) enable certain optimizations. It can be useful to improve the performance of code in continuation passing style.

If oneShot is used wrongly, then it may be that computations whose result that would otherwise be shared are re-evaluated every time they are used. Otherwise, the use of oneShot is safe.

oneShot is representation-polymorphic: the type variables may refer to lifted or unlifted types.

valuerunRW# :: (State# RealWorld -> o) -> o
#

Apply a function to a State# RealWorld token. When manually applying a function to realWorld#, it is necessary to use NOINLINE to prevent semantically undesirable floating. runRW# is inlined, but only very late in compilation after all floating is complete.

classclass DataToTag (a :: TYPE ('BoxedRep lev)) where
#

dataToTag# evaluates its argument and returns the index (starting at zero) of the constructor used to produce that argument. Any algebraic data type with all of its constructors in scope may be used with dataToTag#.

Example2 expressions
dataToTag# (Left ())0#dataToTag# (Right undefined)1#

Methods

classclass WithDict (cls :: Constraint) meth where
#

The constraint WithDict cls meth can be solved when evidence for the constraint cls can be provided in the form of a dictionary of type meth. This requires cls to be a class constraint whose single method has type meth.

For more (important) details on how this works, see Note [withDict] in GHC.Tc.Instance.Class in GHC.

Methods

Functions over Bool

6 declarations
value(&&) :: Bool -> Bool -> Bool
#

Boolean "and", lazy in the second argument

value(||) :: Bool -> Bool -> Bool
#

Boolean "or", lazy in the second argument

datadata Void
#

Uninhabited data type

Instances10Eq, Data, Ord, Read, Show, Ix, …
  • Eq VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Data VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Ord VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Read VoidDefined in ghc-internal-9.1003.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-9.1003.0 · GHC.Internal.Show
  • Ix VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Generic VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Semigroup VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Exception VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception.Type
  • type Rep Void = D1 ('MetaData "Void" "GHC.Internal.Base" "ghc-internal" 'False) V1Defined in ghc-internal-9.1003.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.

Semigroup/Monoid

2 declarations
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 = stimesIdempotent or stimes = 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 ":)"
Instances64Semigroup, …
  • Semigroup ByteArrayDefined in base-4.20.2.0 · Data.Array.Byte
  • Semigroup VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Semigroup AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Semigroup AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Semigroup EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types
  • Semigroup EventLifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types
  • Semigroup LifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types
  • Semigroup ExceptionContextDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception.Context
  • Semigroup OrderingDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Semigroup ()Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid m => Semigroup (WrappedMonoid m)Defined in base-4.20.2.0 · Data.Semigroup
  • Semigroup (FromMaybe b)Defined in base-4.20.2.0 · Data.Foldable1
  • Semigroup (NonEmptyDList a)Defined in base-4.20.2.0 · Data.Foldable1
  • Semigroup (Comparison a)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    (<>) on comparisons combines results with (<>) @Ordering. Without newtypes this equals liftA2 (liftA2 (<>)).

    (<>) :: Comparison a -> Comparison a -> Comparison a
    Comparison cmp <> Comparison cmp' = Comparison a a' ->
      cmp a a' <> cmp a a'
    
  • Semigroup (Equivalence a)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    (<>) on equivalences uses logical conjunction (&&) on the results. Without newtypes this equals liftA2 (liftA2 (&&)).

    (<>) :: Equivalence a -> Equivalence a -> Equivalence a
    Equivalence equiv <> Equivalence equiv' = Equivalence a b ->
      equiv a b && equiv' a b
    
  • Semigroup (Predicate a)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    (<>) on predicates uses logical conjunction (&&) on the results. Without newtypes this equals liftA2 (&&).

    (<>) :: Predicate a -> Predicate a -> Predicate a
    Predicate pred <> Predicate pred' = Predicate a ->
      pred a && pred' a
    
  • Semigroup (First a)Defined in base-4.20.2.0 · Data.Semigroup
  • Semigroup (Last a)Defined in base-4.20.2.0 · Data.Semigroup
  • Semigroup (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Semigroup (First a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Semigroup (Last a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Semigroup (Endo a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Semigroup [a]Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Semigroup a => Semigroup (JoinWith a)Defined in base-4.20.2.0 · Data.Foldable1
  • Semigroup a => Semigroup (STM a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Semigroup a => Semigroup (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identity
  • Semigroup a => Semigroup (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Ord
  • Semigroup a => Semigroup (Dual a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Semigroup a => Semigroup (Maybe a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Semigroup a => Semigroup (IO a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Semigroup a => Semigroup (a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Semigroup p => Semigroup (Par1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Bits a => Semigroup (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Bits a => Semigroup (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Bits a => Semigroup (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • FiniteBits a => Semigroup (Iff a)Defined in ghc-internal-9.1003.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.

  • Num a => Semigroup (Product a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Num a => Semigroup (Sum a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Ord a => Semigroup (Max a)Defined in base-4.20.2.0 · Data.Semigroup
  • Ord a => Semigroup (Min a)Defined in base-4.20.2.0 · Data.Semigroup
  • Ord a => Semigroup (Max a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils
  • Ord a => Semigroup (Min a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils
  • (Generic a, Semigroup (Rep a ())) => Semigroup (Generically a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Semigroup (Either a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Either
  • Semigroup (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Semigroup (U1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Semigroup (V1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Semigroup a => Semigroup (Op a b)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    (<>) @(Op a b) without newtypes is (<>) @(b->a) = liftA2 (<>). This lifts the Semigroup operation (<>) over the output of a.

    (<>) :: Op a b -> Op a b -> Op a b
    Op f <> Op g = Op a -> f a <> g a
    
  • Semigroup a => Semigroup (ST s a)Defined in ghc-internal-9.1003.0 · GHC.Internal.ST
  • Semigroup b => Semigroup (a -> b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • (Semigroup a, Semigroup b) => Semigroup (a, b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Alternative f => Semigroup (Alt f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Semigroup (f p) => Semigroup (Rec1 f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Semigroup a => Semigroup (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const
  • (Applicative f, Semigroup a) => Semigroup (Ap f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Semigroup c => Semigroup (K1 i c p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Semigroup (f a), Semigroup (g a)) => Semigroup (Product f g a)Defined in base-4.20.2.0 · Data.Functor.Product
  • (Semigroup (f p), Semigroup (g p)) => Semigroup ((:*:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Semigroup (f (g a)) => Semigroup (Compose f g a)Defined in base-4.20.2.0 · Data.Functor.Compose
  • Semigroup (f (g p)) => Semigroup ((:.:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Semigroup (f p) => Semigroup (M1 i c f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
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!"
Instances55Monoid, …
  • Monoid ByteArrayDefined in base-4.20.2.0 · Data.Array.Byte
  • Monoid AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types
  • Monoid EventLifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types
  • Monoid LifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types

    mappend takes the longer of two lifetimes.

  • Monoid ExceptionContextDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception.Context
  • Monoid OrderingDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid ()Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid (Comparison a)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    mempty on comparisons always returns EQ. Without newtypes this equals pure (pure EQ).

    mempty :: Comparison a
    mempty = Comparison _ _ -> EQ
    
  • Monoid (Equivalence a)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    mempty on equivalences always returns True. Without newtypes this equals pure (pure True).

    mempty :: Equivalence a
    mempty = Equivalence _ _ -> True
    
  • Monoid (Predicate a)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    mempty on predicates always returns True. Without newtypes this equals pure True.

    mempty :: Predicate a
    mempty = _ -> True
    
  • Monoid (First a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Monoid (Last a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Monoid (Endo a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid [a]Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid a => Monoid (STM a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Monoid a => Monoid (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identity
  • Monoid a => Monoid (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Ord
  • Monoid a => Monoid (Dual a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid a => Monoid (IO a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid a => Monoid (a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid m => Monoid (WrappedMonoid m)Defined in base-4.20.2.0 · Data.Semigroup
  • Monoid p => Monoid (Par1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Semigroup a => Monoid (Maybe a)Defined in ghc-internal-9.1003.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-9.1003.0 · GHC.Internal.Data.Bits
  • Bits a => Monoid (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • FiniteBits a => Monoid (And a)Defined in ghc-internal-9.1003.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-9.1003.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.

  • Num a => Monoid (Product a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Num a => Monoid (Sum a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Ord a => Monoid (Max a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils
  • Ord a => Monoid (Min a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils
  • (Generic a, Monoid (Rep a ())) => Monoid (Generically a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Ord a, Bounded a) => Monoid (Max a)Defined in base-4.20.2.0 · Data.Semigroup
  • (Ord a, Bounded a) => Monoid (Min a)Defined in base-4.20.2.0 · Data.Semigroup
  • Monoid (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Monoid (U1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Monoid a => Monoid (Op a b)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    mempty @(Op a b) without newtypes is mempty @(b->a) = _ -> mempty.

    mempty :: Op a b
    mempty = Op _ -> mempty
    
  • Monoid a => Monoid (ST s a)Defined in ghc-internal-9.1003.0 · GHC.Internal.ST
  • Monoid b => Monoid (a -> b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • (Monoid a, Monoid b) => Monoid (a, b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Alternative f => Monoid (Alt f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid (f p) => Monoid (Rec1 f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Monoid a => Monoid (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const
  • (Applicative f, Monoid a) => Monoid (Ap f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid c => Monoid (K1 i c p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Monoid (f a), Monoid (g a)) => Monoid (Product f g a)Defined in base-4.20.2.0 · Data.Functor.Product
  • (Monoid (f p), Monoid (g p)) => Monoid ((:*:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid (f (g a)) => Monoid (Compose f g a)Defined in base-4.20.2.0 · Data.Functor.Compose
  • Monoid (f (g p)) => Monoid ((:.:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Monoid (f p) => Monoid (M1 i c f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base

Functors

32 declarations
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 instance that allows both the last and the penultimate parameters to be mapped over.

    Examples

    Convert from a Maybe Int to a Maybe String using show:

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

    Convert from an Either Int Int to an Either Int String using 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 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
Instances69Functor, …
  • Functor ComplexDefined in base-4.20.2.0 · Data.Complex
  • Functor FirstDefined in base-4.20.2.0 · Data.Semigroup
  • Functor LastDefined in base-4.20.2.0 · Data.Semigroup
  • Functor MaxDefined in base-4.20.2.0 · Data.Semigroup
  • Functor MinDefined in base-4.20.2.0 · Data.Semigroup
  • Functor ArgDescrDefined in base-4.20.2.0 · System.Console.GetOpt
  • Functor ArgOrderDefined in base-4.20.2.0 · System.Console.GetOpt
  • Functor OptDescrDefined in base-4.20.2.0 · System.Console.GetOpt
  • Functor NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor STMDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Functor HandlerDefined in ghc-internal-9.1003.0 · GHC.Internal.Control.Exception
  • Functor IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identity
  • Functor FirstDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Functor LastDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Functor DownDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Ord
  • Functor DualDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Functor ProductDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Functor SumDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Functor ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipList
  • Functor NoIODefined in ghc-internal-9.1003.0 · GHC.Internal.GHCi
  • Functor Par1Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor MaybeDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor PDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • Functor ReadPDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • Functor ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • Functor SoloDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor IODefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor []Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Functor U1Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor V1Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (Arg a)Defined in base-4.20.2.0 · Data.Semigroup
  • Functor (Array i)Defined in ghc-internal-9.1003.0 · GHC.Internal.Arr
  • Functor (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.ST.Lazy.Imp
  • Functor (Either a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Either
  • Functor (StateL s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils
  • Functor (StateR s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils
  • Functor (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.ST
  • Functor (Tuple2 a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monad m => Functor (WrappedMonad m)Defined in base-4.20.2.0 · Control.Applicative
  • Arrow a => Functor (ArrowMonad a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • Functor (Const m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const
  • Functor (URec Char)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (URec Double)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (URec Float)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (URec Int)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (URec Word)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (URec (Ptr ()))Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (Tuple3 a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor f => Functor (Ap f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Functor f => Functor (Alt f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Functor f => Functor (Rec1 f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor m => Functor (Kleisli m a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • Monad m => Functor (StateT s m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils
  • Arrow a => Functor (WrappedArrow a b)Defined in base-4.20.2.0 · Control.Applicative
  • (Generic1 f, Functor (Rep1 f)) => Functor (Generically1 f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (K1 i c)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (Tuple4 a b c)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor ((->) r)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • (Functor f, Functor g) => Functor (Product f g)Defined in base-4.20.2.0 · Data.Functor.Product
  • (Functor f, Functor g) => Functor (Sum f g)Defined in base-4.20.2.0 · Data.Functor.Sum
  • (Functor f, Functor g) => Functor (f :*: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Functor f, Functor g) => Functor (f :+: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (Tuple5 a b c d)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor f => Functor (M1 i c f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Functor f, Functor g) => Functor (Compose f g)Defined in base-4.20.2.0 · Data.Functor.Compose
  • (Functor f, Functor g) => Functor (f :.: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Functor (Tuple6 a b c d e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Functor (Tuple7 a b c d e f)Defined in ghc-internal-9.1003.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 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.

Instances51Applicative, …
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.

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.

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, 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', but some people may refer to it as 'flatMap', which results from it being equivialent 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.

Instances42Monad, …
  • Monad ComplexDefined in base-4.20.2.0 · Data.Complex
  • Monad FirstDefined in base-4.20.2.0 · Data.Semigroup
  • Monad LastDefined in base-4.20.2.0 · Data.Semigroup
  • Monad MaxDefined in base-4.20.2.0 · Data.Semigroup
  • Monad MinDefined in base-4.20.2.0 · Data.Semigroup
  • Monad NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monad STMDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Monad IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identity
  • Monad FirstDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Monad LastDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Monad DownDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Ord
  • Monad DualDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monad ProductDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monad SumDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monad NoIODefined in ghc-internal-9.1003.0 · GHC.Internal.GHCi
  • Monad Par1Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Monad MaybeDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monad PDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • Monad ReadPDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadP
  • Monad ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • Monad SoloDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monad IODefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monad []Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monad ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Monad U1Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Monad (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.ST.Lazy.Imp
  • Monad (Either e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Either
  • Monad (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.ST
  • Monad m => Monad (WrappedMonad m)Defined in base-4.20.2.0 · Control.Applicative
  • Monoid a => Monad (Tuple2 a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • ArrowApply a => Monad (ArrowMonad a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • Monad f => Monad (Ap f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Monad f => Monad (Alt f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monad f => Monad (Rec1 f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Monad m => Monad (Kleisli m a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • Monad m => Monad (StateT s m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils
  • (Monoid a, Monoid b) => Monad (Tuple3 a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monad ((->) r)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • (Monad f, Monad g) => Monad (Product f g)Defined in base-4.20.2.0 · Data.Functor.Product
  • (Monad f, Monad g) => Monad (f :*: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Monoid a, Monoid b, Monoid c) => Monad (Tuple4 a b c)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monad f => Monad (M1 i c f)Defined in ghc-internal-9.1003.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.

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.

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
Examples
Example1 expression
pure (\x y z -> x + y * z) `ap` Just 1 `ap` Just 5 `ap` Just 10Just 51
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.

Instances23Alternative, …
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 = (<|>)
    
Instances17MonadPlus, …
datadata NonEmpty a
#

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

Constructors

  • a :| [a]infixr 5
Instances24Monad, 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]
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 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 Char.

Miscellanea

13 declarations
valueotherwise :: Bool
#

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

 f x | x < 0     = ...
     | otherwise = ...
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 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.

IO

5 declarations

Low-level integer utilities

25 declarations
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)