A functor in the sense used in functional programming, which means a function f : Type u → Type v
has a way of mapping a function over its contents. This map
operator is written <$>
, and
overloaded via Functor
instances.
This map
function should respect identity and function composition. In other words, for all terms
v : f α
, it should be the case that:
-
id <$> v = v
-
For all functions
h : β → γ
andg : α → β
,(h ∘ g) <$> v = h <$> g <$> v
While all Functor
instances should live up to these requirements, they are not required to prove
that they do. Proofs may be required or provided via the LawfulFunctor
class.
Assuming that instances are lawful, this definition corresponds to the category-theoretic notion of functor in the special case where the category is the category of types and functions between them.
Instance Constructor
Functor.mk.{u, v}
Methods
map : {α β : Type u} → (α → β) → f α → f β
Applies a function inside a functor. This is used to overload the <$>
operator.
When mapping a constant function, use Functor.mapConst
instead, because it may be more
efficient.
Conventions for notations in identifiers:
-
The recommended spelling of
<$>
in identifiers ismap
.
mapConst : {α β : Type u} → α → f β → f α
Mapping a constant function.
Given a : α
and v : f α
, mapConst a v
is equivalent to Function.const _ a <$> v
. For some
functors, this can be implemented more efficiently; for all other functors, the default
implementation may be used.