Exercises part 1
-
It is interesting that
Traversablehas aFunctorconstraint. Proof that everyTraversableis automatically aFunctorby implementingmapin terms oftraverse.Hint: Remember
Control.Monad.Identity. -
Likewise, proof that every
Traversableis aFoldableby implementingfoldMapin terms ofTraverse.Hint: Remember
Control.Applicative.Const. -
To gain some routine, implement
Traversable'forList1,Either e, andMaybe. -
Implement
TraversableforList01 ne:data List01 : (nonEmpty : Bool) -> Type -> Type where Nil : List01 False a (::) : a -> List01 False a -> List01 ne a -
Implement
Traversablefor rose trees. Try to satisfy the totality checker without cheating.record Tree a where constructor Node value : a forest : List (Tree a) -
Implement
TraversableforCrud i:data Crud : (i : Type) -> (a : Type) -> Type where Create : (value : a) -> Crud i a Update : (id : i) -> (value : a) -> Crud i a Read : (id : i) -> Crud i a Delete : (id : i) -> Crud i a -
Implement
TraversableforResponse e i:data Response : (e, i, a : Type) -> Type where Created : (id : i) -> (value : a) -> Response e i a Updated : (id : i) -> (value : a) -> Response e i a Found : (values : List a) -> Response e i a Deleted : (id : i) -> Response e i a Error : (err : e) -> Response e i a -
Like
Functor,ApplicativeandFoldable,Traversableis closed under composition. Proof this by implementingTraversableforCompandProduct:record Comp (f,g : Type -> Type) (a : Type) where constructor MkComp unComp : f (g a) record Product (f,g : Type -> Type) (a : Type) where constructor MkProduct fst : f a snd : g a