Question: Haskell Question Given data Tree a = Leaf | Branch a (Tree a) (Tree a) deriving (Show, Eq) foldTree :: b -> (a -> b

Haskell Question

Given

data Tree a = Leaf

| Branch a (Tree a) (Tree a) deriving (Show, Eq)

foldTree :: b -> (a -> b -> b -> b) -> Tree a -> b

foldTree e _ Leaf = e

foldTree e n (Branch a n1 n2) = n a (foldTree e n n1) (foldTree e n n2)

mapTree :: (a -> b) -> Tree a -> Tree b

mapTree f = foldTree Leaf (\x t1 t2 -> Branch (f x) t1 t2)

1(a) Implement takeWhileTree, applied to a predicate p and a tree t, returns the largest prefix tree of t (possibly empty) where all elements satisfy p.

Haskell Question Given data Tree a = Leaf | Branch a (Tree

1(b) Implement zipTree f xs ys that returns the tree obtained by applying f to each pair of corresponding elements of xs and ys. If one branch is longer than the other, then the extra elements are ignored.

a) (Tree a) deriving (Show, Eq) foldTree :: b -> (a ->

Thank you!

Main > tree1 = Branch 1 (Branch 2 Leaf Leaf) (Branch 3 Leaf Leaf) Main > takeWhileTree ( takeWhileTree ( tree2 = Branch 4 (Branch 2 Leaf Leaf) (Branch 3 Leaf Leaf) Main > takeWhileTree ( zipTree (+) (Branch 1 Leaf (Branch 2 Leaf Leaf)) (Branch 3 Leaf Leaf) (Branch 4 Leaf Leaf) Main > tree1 = Branch 1 (Branch 2 Leaf Leaf) (Branch 3 Leaf Leaf) Main > takeWhileTree ( takeWhileTree ( tree2 = Branch 4 (Branch 2 Leaf Leaf) (Branch 3 Leaf Leaf) Main > takeWhileTree ( zipTree (+) (Branch 1 Leaf (Branch 2 Leaf Leaf)) (Branch 3 Leaf Leaf) (Branch 4 Leaf Leaf)

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 Accounting Questions!