id package:ghc-internal

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

>>> length $ filter id [True, True, False, True]
3
>>> Just (Just 3) >>= id
Just 3
>>> foldr id 0 [(^3), (*5), (+2)]
1000
The identity morphism. Implementations should satisfy two laws:
  • Right identity f . id = f
  • Left identity id . f = f
These essentially state that id should "do nothing".
The identity functor and monad. This trivial type constructor serves two purposes:
  • It can be used with functions parameterized by functor or monad classes.
  • It can be used as a base monad to which a series of monad transformers may be applied to construct a composite monad. Most monad transformer modules include the special case of applying the transformer to Identity. For example, State s is an abbreviation for StateT s Identity.
Identity functor and monad. (a non-strict monad)

Examples

>>> fmap (+1) (Identity 0)
Identity 1
>>> Identity [1, 2, 3] <> Identity [4, 5, 6]
Identity [1,2,3,4,5,6]
>>> do
x <- Identity 10
y <- Identity (x + 5)
pure (x + y)
Identity 25
Haskell identifier, e.g. foo, Baz
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following: You can alternatively define mconcat instead of mempty, in which case the laws are: 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. Sum and Product. NOTE: Semigroup is a superclass of Monoid since base-4.11.0.0.
(In a non-concurrent implementation, this can be a singleton type, whose (unique) value is returned by myThreadId#. The other operations can be omitted.)
Uninhabited data type
Deprecated: Void# is now an alias for the unboxed tuple (# #).
Divide two vectors element-wise.
Divide two vectors element-wise.
Divide two vectors element-wise.
Divide two vectors element-wise.
Divide two vectors element-wise.
Divide two vectors element-wise.
Read a 32-bit character from immutable array; offset in 4-byte words.
Read a 32-bit character from immutable address; offset in 4-byte words. On some platforms, the access may fail for an insufficiently aligned Addr#.
Read a 32-bit character from immutable array; offset in bytes.
Read a 32-bit character from immutable address; offset in bytes.
Read a 32-bit character from mutable array; offset in 4-byte words. Warning: this can fail with an unchecked exception.
Read a 32-bit character from mutable address; offset in 4-byte words. On some platforms, the access may fail for an insufficiently aligned Addr#. Warning: this can fail with an unchecked exception.