Exercises part 2
Implement the following functions in a provably total way without "cheating". Note: It is not necessary to implement these in a tail recursive way.
-
Implement function
depth
for rose trees. This should return the maximal number ofNode
constructors from the current node to the farthest child node. For instance, the current node should be at depth one, all its direct child nodes are at depth two, their immediate child nodes at depth three and so on. -
Implement interface
Eq
for rose trees. -
Implement interface
Functor
for rose trees. -
For the fun of it: Implement interface
Show
for rose trees. -
In order not to forget how to program with dependent types, implement function
treeToVect
for converting a rose tree to a vector of the correct size.Hint: Make sure to follow the same recursion scheme as in the implementation of
treeSize
. Otherwise, this might be very hard to get to work.