Exercises part 1
-
It is interesting that
Traversable
has aFunctor
constraint. Proof that everyTraversable
is automatically aFunctor
by implementingmap
in terms oftraverse
.Hint: Remember
Control.Monad.Identity
. -
Likewise, proof that every
Traversable
is aFoldable
by implementingfoldMap
in terms ofTraverse
.Hint: Remember
Control.Applicative.Const
. -
To gain some routine, implement
Traversable'
forList1
,Either e
, andMaybe
. -
Implement
Traversable
forList01 ne
:data List01 : (nonEmpty : Bool) -> Type -> Type where Nil : List01 False a (::) : a -> List01 False a -> List01 ne a
-
Implement
Traversable
for rose trees. Try to satisfy the totality checker without cheating.record Tree a where constructor Node value : a forest : List (Tree a)
-
Implement
Traversable
forCrud 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
Traversable
forResponse 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
,Applicative
andFoldable
,Traversable
is closed under composition. Proof this by implementingTraversable
forComp
andProduct
: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