= Solution
Use the input <list> as the seed of the <tree unfold>:
``
buildUnfold :: [a] -> Tree a
buildUnfold = unfold step
where
step [] = error "build: empty input"
step [x] = Left x
step xs = Right (split (length xs `div` 2) xs)
``
On a singleton seed, `unfold` produces the same leaf as `build`; on a longer finite seed, it recursively builds the same two pieces. <Induction> on input length proves \b[`buildUnfold = build` on finite nonempty inputs]. The empty-input qualification remains essential: a <tree unfold> cannot supply a missing empty-tree constructor.
Back to article page