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 buildUnfold = build on finite nonempty inputs. The empty-input qualification remains essential: a tree unfold cannot supply a missing empty-tree constructor. Articles by others on the same topic
There are currently no matching articles.