は、再帰的なツリー構造変更の葉の値が与えられ
data Tree = Leaf Int | Node Tree Tree deriving Show
ある木の構造を維持しながら、私は木の構造を維持する方法でそれを正規化するように、しかしで整数を作るだろう葉は深さ順に連続している。どうすればこれを達成できますか?
myTree = Node (Leaf 3) (Node (Leaf 5) (Leaf 2))
myTree' = normalize myTree
-- preserve tree structure, but make Ints sequential in depths-first traversal
normalize :: Tree -> Tree
normalize = id -- todo: implement
main = do
print myTree -- prints : Node (Leaf 3) (Node (Leaf 5) (Leaf 2))
print myTree' -- should print: Node (Leaf 1) (Node (Leaf 2) (Leaf 3))
[素晴らしい作品](http://ideone.com/bfO62J)(わずかに簡略化された状態機能)。ありがとうございました。 –