The constant functor $\text{Const}\;\alpha\;\beta$: carries a value of type $\alpha$, with a phantom type parameter $\beta$.
$$\text{Const}\;\alpha\;\beta \;\cong\; \alpha$$
As a functor in $\beta$, mapping is a no-op (the $\beta$ is phantom).
As an applicative (when $\alpha$ has Append), <*> accumulates the $\alpha$ values.
This makes Const the key ingredient for implementing foldMap via traverse.
- getConst : α
Extract the wrapped value.
Instances For
BEq instance for Const α β: compares the underlying $\alpha$ values,
ignoring the phantom $\beta$.
Equations
- Data.Functor.Const.instBEq = { beq := fun (a b : Data.Functor.Const α β) => a.getConst == b.getConst }
Ord instance for Const α β: orders by the underlying $\alpha$ values.
Equations
- Data.Functor.Const.instOrd = { compare := fun (a b : Data.Functor.Const α β) => compare a.getConst b.getConst }
Repr instance for Const α β: delegates to the underlying $\alpha$ representation.
Equations
- Data.Functor.Const.instRepr = { reprPrec := fun (c : Data.Functor.Const α β) (p : Nat) => reprPrec c.getConst p }
ToString instance for Const α β: delegates to ToString α.
Equations
- Data.Functor.Const.instToString = { toString := fun (c : Data.Functor.Const α β) => toString c.getConst }
Functor instance for Const α: mapping over the phantom parameter is a no-op.
$$\text{fmap}\;f\;(\text{Const}\;a) = \text{Const}\;a$$
The function $f : \beta \to \gamma$ is discarded since no $\beta$ value exists to apply it to.
Equations
- Data.Functor.Const.instFunctor = { map := fun {α_1 β : Type ?u.18} (x : α_1 → β) (c : Data.Functor.Const α α_1) => { getConst := c.getConst } }
Pure instance for Const α (requires Append α and Inhabited α):
$\text{pure}\;\_= \text{Const}(\text{default})$.
The value is the monoidal identity (default), since pure should be
the identity element for applicative combination.