Question: Flattening and Elem Consider the (non tail-recursive) function flatten that flattens a tree into a list: flatten :: Tree a ->a] flatten Nul = []

 Flattening and Elem Consider the (non tail-recursive) function flatten that flattens

Flattening and Elem Consider the (non tail-recursive) function flatten that flattens a tree into a list: flatten :: Tree a ->a] flatten Nul = [] flatten (Node l x r) - (flatten 1) ++ [x] ++ (flatten r) SF1 - SF2 together with the function elemT given by elemT : : Eg a => a-> Tree a-> Bool elemT y Nul elemT y (Node l x r) = False ET1 ET2 | otherwise = (elemT y 1) 11 (elemT y r) -- ET3 = True Show, using tree induction, that elmT e t = elem e (flatten t) for all t of type Tree a and all e of type a. Hint. You may want to use Exercise 5 on Tutorial Sheet 4. You may also want to use the equality proved there. It may be helpful to first establish the value of elem e [x] Clearly state what you need to prove for the base case, the inductive hypothesis, and what you need to show in the step case

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!