Containers, when interpreted as type descriptors, hold a shape for data in
their first argument, and positions inside the aforementionned shape. In the
case of list, the shape is given by a natural number which describes its length.
The positions are all the possibles values for a given shape. Since the shape is
the number of elements, the positions are given by a type that has the same
number of inhabitants as the length of the list.
This way, a list of 3 elements, hosts 3 values.
public exportListCont : ContainerListCont = (len : Nat) !> Fin len
Again, using the extension \defref{def:extension} we obtain the corresponding
functor in Set
public exportTyList : Type -> TypeTyList = Ex ListCont
We can now construct inhabitants for our bespoke list type, for example, the
constructors for the empty list, and the constructor for cons:
public exportNil : TyList aNil = MkEx Z absurdpublic exportCons : a -> TyList a -> TyList aCons x ls = MkEx (S ls.ex1) (elimFin x ls.ex2)
Lemma
[[ListCont]] is isomorphic to List.
public export coveringtyListToList : TyList x -> List xtyListToList (MkEx Z y) = []tyListToList (MkEx (S n) y) = y FZ :: (tyListToList (MkEx n (y . FS)))public exportlistToTyList : List x -> TyList xlistToTyList [] = NillistToTyList (y :: xs) = Cons y (listToTyList xs)public export coveringtoFrom : {0 a : Type} -> (x : List a) -> tyListToList (listToTyList x) = xtoFrom [] = RefltoFrom (x :: xs) = cong (x ::) (cong tyListToList exEta `trans` toFrom xs)public export covering0 fromTo : (v : TyList x) -> listToTyList (tyListToList v) = vfromTo (MkEx Z f) = cong2Dep' MkEx Refl (allUninhabited _ _)fromTo (MkEx (S n) f) = let pat = (fromTo (MkEx n (f . FS))) in exEqToEq $ MkExEq (cong S $ sym $ exP1 $ sym pat) (\xx => Calc $ |~ elimFin (f FZ) ((listToTyList (tyListToList (MkEx n (f . FS)))).ex2) xx ~~ elimFin (f FZ) ((MkEx {cont = ListCont} n (f . FS)).ex2) (transport Fin (cong S (sym (exP1 (sym pat)))) xx) ...(rewrite pat in cong (elimFin (f FZ) (f . FS)) (sym $ applyTransport ? ?)) ~~ elimFin (f FZ) (f . FS) (transport Fin (cong S (sym (exP1 (sym pat)))) xx) ...(Refl) ~~ f (transport Fin (cong S (sym (exP1 (sym pat)))) xx) ...(elimFinF f ?) )public export coveringtyListIso : TyList x ≅ List xtyListIso = MkIso tyListToList listToTyList toFrom fromTo