Challenge 2: A Functor Instance for Tree a — Possible Solution ==================================================================== Main.hs: data Tree a = Leaf | Node (Tree a) a (Tree a) deriving (Show) instance Functor Tree where fmap _ Leaf = Leaf fmap f (Node l v r) = Node (fmap f l) (f v) (fmap f r) sampleTree :: Tree Int sampleTree = Node (Node Leaf 1 Leaf) 2 (Node Leaf 3 Leaf) main :: IO () main = print (fmap (*10) sampleTree) Output: Node (Node Leaf 10 Leaf) 20 (Node Leaf 30 Leaf) Explanation: The Functor instance mirrors Tree's own recursive shape exactly: Leaf maps to Leaf (nothing to transform in an empty subtree), and a Node recursively fmaps over both its left and right subtrees while applying f directly to its own value. Calling fmap (*10) on sampleTree multiplies every value in the tree by 10 -- 1, 2, and 3 become 10, 20, and 30 -- while the tree's overall shape (which nodes are Leaf vs Node, and where) stays completely unchanged. WHY THIS WORKS AS AN ANSWER ------------------------------ This writes the exact Functor instance the chapter introduces for Tree a, applies it to a real multi-node tree (not just a trivial single-node example), and confirms both the transformed values and the preserved tree structure in the output.