Proposition

is a functor in

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

MaybeCoprod : Endo Cont
MaybeCoprod = applyL {a = Cont, b = Cont} One CoprodContBifunctor

Those two previous definitions are isomorphic, because they are functors, we define a natural isomorphism between them.

Lemma

and are isomorphic.

AnyCoprodIso : ContIso (Any.Maybe x) (MaybeCoprod .mapObj x)
AnyCoprodIso = MkGenIso toCoprod fromCoprod toFrom fromTo
  where
    toCoprod : {0 x : Container} -> Any.Maybe x =%> MaybeCoprod .mapObj x
    toCoprod = maybeToCoprod <! (\case Nothing => absurd
                                       (Just y) => Aye)
 
    fromCoprod : {0 x : Container} -> MaybeCoprod .mapObj x =%> Any.Maybe x
    fromCoprod = coprodToMaybe <! (\case (<+ y) => absurd
                                         (+> y) => .unwrap)
 
    toFrom : {x : Container} ->
             (toCoprod {x} |%> fromCoprod {x}) <%≡%> identity (Any.Maybe x)
    toFrom = MkDepLensEq
        (\case Nothing => Refl
               (Just y) => Refl)
        (\case Nothing => \yx => absurd yx
               (Just y) => \(Aye z) => Refl)
 
    fromTo : {x : Container} ->
             (fromCoprod {x} |%> toCoprod {x}) <%≡%> identity (MaybeCoprod .mapObj x)
    fromTo = MkDepLensEq
        (\case (<+ ()) => Refl
               (+> x) => Refl)
        (\case (<+ ()) => \y => absurd y
               (+> x) => \_ => Refl)

Finally, there is a third way to define the maybe functor and that is by using the sequencing product and the maybe container \defref{def:maybecont}.

Proposition

There is a Maybe functor defined by

public export
MaybeSeq : Endo Cont
MaybeSeq = 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

is a functor in

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

  MaybeAllSeq : Endo Cont
  MaybeAllSeq = applyL {a = ContCart, b = Cont} MaybeCont ForallSeqBifunctor

Proposition

There is a Maybe functor defined by

  MaybeCoprod : Endo Cont
  MaybeCoprod = applyL {a = Cont, b = Cont} I CoprodContBifunctor

Like before, , and are all isomorphic.

Lemma

and are isomorphic

Lemma

and and are isomorphic