Identity

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
Identity functor and monad. (a non-strict monad)
  • Computation type: Simple function application.
  • Binding strategy: The bound function is applied to the input value. Identity x >>= f == f x
  • Useful for: Monads can be derived from monad transformers applied to the Identity monad.
  • Zero and plus: None.
  • Example type: Identity a
The Identity monad is a monad that does not embody any computational strategy. It simply applies the bound function to its input without any modification. Computationally, there is no reason to use the Identity monad instead of the much simpler act of simply applying functions to their arguments. The purpose of the Identity monad is its fundamental role in the theory of monad transformers. Any monad transformer applied to the Identity monad yields a non-transformer version of that monad.
The identity monad transformer. This is useful for functions parameterized by a monad transformer.
Identity functor and monad. (a non-strict monad)
This is identical to the Identity from Data.Functor.Identity in "base" except for its Show instance.
  • Computation type: Simple function application.
  • Binding strategy: The bound function is applied to the input value. Identity x >>= f == Identity (f x)
  • Useful for: Monads can be derived from monad transformers applied to the Identity monad.
  • Zero and plus: None.
  • Example type: Identity a
The Identity monad is a monad that does not embody any computational strategy. It simply applies the bound function to its input without any modification. Computationally, there is no reason to use the Identity monad instead of the much simpler act of simply applying functions to their arguments. The purpose of the Identity monad is its fundamental role in the theory of monad transformers. Any monad transformer applied to the Identity monad yields a non-transformer version of that monad.
TextShow instance for Identity values. Since: 2
Identity functor and monad. (a non-strict monad)
Identity re-export, with a compat wrapper for older version of base that do not have Data.Functor.Identity
Each inhabitant is either a knave or a knight
The identiy projection. This can be combined with PrReflectX and PrReflectY in the list of projection properties.