Tree building function in Haskell (Homework)
问题 data Tree a = Leaf | Node (Tree a) a (Tree a) deriving (Eq, Show) unfoldTree:: (b -> Maybe (b, a, b)) -> b -> Tree a unfoldTree f b = case f b of Nothing -> Leaf Just (lt, x, rt) -> Node (unfoldTree f lt) x (unfoldTree f rt) Given the two piece of information above, I'm asked to implement a tree building function. and my attempt is treeBuild :: Integer -> Tree Integer treeBuild 0 = Leaf treeBuild n = treeUnfold (\b -> if b < 2^n-1 then Just(2*b, b + 1, 2*b + 1) else Nothing) 0 The base case