namespace Any public export mapMaybe : a =%> b -> Any.Maybe a =%> Any.Maybe b mapMaybe x = map x.fwd <! (\y, z => anyFunctorMap x.fwd x.bwd y z) public export MaybeF : Endo Cont MaybeF = MkFunctor Any.Maybe (\_, _ => Any.mapMaybe) -- proofs in appendix
In functional programming, the Maybe type can also be conceptualised as Maybe x = 1 + x where
1 is the unit (or terminal) type. This intuition also holds in the category of containers.
Proposition
There is a Maybe functor defined by Maybe1+(A,Aˉ)↦1+(A,Aˉ)
MaybeCoprod : Endo ContMaybeCoprod = applyL {a = Cont, b = Cont} One CoprodContBifunctor
Those two previous definitions are isomorphic, because they are functors, we define a natural
isomorphism between them.
Finally, there is a third way to define the maybe functor and that is by using the sequencing product
and the maybe container MaybeCont \defref{def:maybecont}.
Proposition
There is a Maybe functor defined by Maybe▷(A,Aˉ)=MaybeCont⊳(A,Aˉ)
public exportMaybeSeq : Endo ContMaybeSeq = applyL {a = Cont, b = Cont} MaybeCont Cont.SequenceBifunctor
What if we didn’t use Any but it’s counterpart All? We get similar constructions with similar properties.
Proposition
MaybeAll is a functor in Cont
namespace All public export mapMaybe : a =%> b -> All.Maybe a =%> All.Maybe b mapMaybe x = map x.fwd <! (\y, z => allFunctorMap x.fwd x.bwd y z) public export MaybeF : Endo Cont MaybeF = MkFunctor All.Maybe (\_, _ => All.mapMaybe)
Proposition
There is a Maybe functor defined by Maybe▶c↦MaybeCont▶c