The sum (coproduct) functor $(\text{FunctorSum}\;F\;G)\;\alpha = F\;\alpha + G\;\alpha$.
Holds either an F α (via inl) or a G α (via inr).
Mapping over a sum maps through whichever branch is inhabited.
$$\text{fmap}\;f\;(\text{inl}\;a) = \text{inl}\;(\text{fmap}\;f\;a)$$ $$\text{fmap}\;f\;(\text{inr}\;b) = \text{inr}\;(\text{fmap}\;f\;b)$$
- inl
{F G : Type u → Type v}
{α : Type u}
: F α → FunctorSum F G α
Left injection: wraps an $F\;\alpha$.
- inr
{F G : Type u → Type v}
{α : Type u}
: G α → FunctorSum F G α
Right injection: wraps a $G\;\alpha$.
Instances For
Functor instance for FunctorSum F G: maps through whichever branch is present.
$$\text{fmap}\;f\;(\text{inl}\;a) = \text{inl}\;(\text{fmap}\;f\;a)$$ $$\text{fmap}\;f\;(\text{inr}\;b) = \text{inr}\;(\text{fmap}\;f\;b)$$
Equations
- One or more equations did not get rendered due to their size.
Identity law for sum functors: $\text{fmap}\;\text{id} = \text{id}$.
Proceeds by cases: each branch reduces to the identity law of the respective functor.
Composition law for sum functors: $\text{fmap}\;(f \circ g) = \text{fmap}\;f \circ \text{fmap}\;g$.
Proceeds by cases: each branch reduces to the composition law of the respective functor.