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
mapConst
implementation is equivalent to the default implementation.The
map
implementation preserves identity.The
map
implementation preserves function composition.
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.
seqLeft
is equivalent to the default implementation.seqRight
is equivalent to the default implementation.pure
beforeseq
is equivalent toFunctor.map
.This means that
pure
really is pure when occurring immediately prior toseq
.Mapping a function over the result of
pure
is equivalent to applying the function underpure
.This means that
pure
really is pure with respect toFunctor.map
.pure
afterseq
is equivalent toFunctor.map
.This means that
pure
really is pure when occurring just afterseq
.- seq_assoc {α β γ : Type u} (x : f α) (g : f (α → β)) (h : f (β → γ)) : h <*> (g <*> x) = Function.comp <$> h <*> g <*> x
seq
is associative.Changing the nesting of
seq
calls while maintaining the order of computations results in an equivalent computation. This means thatseq
is not doing any more than sequencing.
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
bind
followed bypure
composed with a function is equivalent to a functorial map.This means that
pure
really is pure after abind
and has no effects.A
bind
followed by a functorial map is equivalent toApplicative
sequencing.This means that the effect sequencing from
Monad
andApplicative
are the same.pure
followed bybind
is equivalent to function application.This means that
pure
really is pure before abind
and has no effects.- bind_assoc {α β γ : Type u} (x : m α) (f : α → m β) (g : β → m γ) : x >>= f >>= g = x >>= fun (x : α) => f x >>= g
bind
is associative.Changing the nesting of
bind
calls while maintaining the order of computations results in an equivalent computation. This means thatbind
is not doing more than data-dependent sequencing.
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.