A functor satisfies the functor laws.
The Functor class contains the operations of a functor, but does not require that instances
prove they satisfy the laws of a functor. A LawfulFunctor instance includes proofs that the laws
are satisfied. Because Functor instances may provide optimized implementations of mapConst,
LawfulFunctor instances must also prove that the optimized implementation is equivalent to the
standard implementation.
The
mapConstimplementation is equivalent to the default implementation.The
mapimplementation preserves identity.The
mapimplementation preserves function composition.
Instances
An applicative functor satisfies the laws of an applicative functor.
The Applicative class contains the operations of an applicative functor, but does not require that
instances prove they satisfy the laws of an applicative functor. A LawfulApplicative instance
includes proofs that the laws are satisfied.
Because Applicative instances may provide optimized implementations of seqLeft and seqRight,
LawfulApplicative instances must also prove that the optimized implementation is equivalent to the
standard implementation.
seqLeftis equivalent to the default implementation.seqRightis equivalent to the default implementation.purebeforeseqis equivalent toFunctor.map.This means that
purereally is pure when occurring immediately prior toseq.Mapping a function over the result of
pureis equivalent to applying the function underpure.This means that
purereally is pure with respect toFunctor.map.pureafterseqis equivalent toFunctor.map.This means that
purereally is pure when occurring just afterseq.- seq_assoc {α β γ : Type u} (x : f α) (g : f (α → β)) (h : f (β → γ)) : h <*> (g <*> x) = Function.comp <$> h <*> g <*> x
seqis associative.Changing the nesting of
seqcalls while maintaining the order of computations results in an equivalent computation. This means thatseqis not doing any more than sequencing.
Instances
Lawful monads are those that satisfy a certain behavioral specification. While all instances of
Monad should satisfy these laws, not all implementations are required to prove this.
LawfulMonad.mk' is an alternative constructor that contains useful defaults for many fields.
- seq_assoc {α β γ : Type u} (x : m α) (g : m (α → β)) (h : m (β → γ)) : h <*> (g <*> x) = Function.comp <$> h <*> g <*> x
A
bindfollowed bypurecomposed with a function is equivalent to a functorial map.This means that
purereally is pure after abindand has no effects.A
bindfollowed by a functorial map is equivalent toApplicativesequencing.This means that the effect sequencing from
MonadandApplicativeare the same.purefollowed bybindis equivalent to function application.This means that
purereally is pure before abindand has no effects.- bind_assoc {α β γ : Type u} (x : m α) (f : α → m β) (g : β → m γ) : x >>= f >>= g = x >>= fun (x : α) => f x >>= g
bindis associative.Changing the nesting of
bindcalls while maintaining the order of computations results in an equivalent computation. This means thatbindis not doing more than data-dependent sequencing.
Instances
Use simp [← bind_pure_comp] rather than simp [map_eq_pure_bind],
as bind_pure_comp is in the default simp set, so also using map_eq_pure_bind would cause a loop.
This is just a duplicate of LawfulApplicative.map_pure,
but sometimes applies when that doesn't.
It is named with a prime to avoid conflict with the inherited field LawfulMonad.map_pure.
This is just a duplicate of Functor.map_map, but sometimes applies when that doesn't.
An alternative constructor for LawfulMonad which has more
defaultable fields in the common case.