Question
In a similar manner, show how the following type of binary trees with data in their nodes can be made into a foldable and traversable type:data Tree a = Leaf | Node (Tree a) a (Tree a)deriving Show
Step 1
The Foldable typeclass provides a generic way to fold (or reduce) a data structure to a single value. To define the Foldable instance for Tree, we need to implement the foldr function. This function takes a binary function and an initial accumulator value, and Show more…
Show all steps
Your feedback will help us improve your experience
Watch the video solution with this free unlock.
EMAIL
PASSWORD