-1
我試圖瞭解樹木中的標籤,但我無法理解。這是我Datentyp的樹:地圖和郵政編碼哈斯克爾的樹
data Tree = Node (Label -> Label) Label [Tree]
type Label = Int
我無法理解真正的,之間有什麼(標籤 - >標籤)的區別和標籤? 我怎樣才能從這些功能得到正確的結果?
tcm :: (Label -> Bool) -> (Label -> Label) -> Tree -> Tree
tzp :: (Label -> Label -> Label) -> Tree -> Tree -> Tree
tmax :: Label -> Tree -> (Label -> Label)
繼承人的例子樹和不同datentyp樹木和類似的功能類似的例子:
t1 = Null
t2 = Tree 2 (Tree 3 Null Null) (Tree 5 Null Null)
t3 = Tree 2 (Tree 3 (Tree 5 Null Null) Null) (Tree 7 Null Null)
data Tree = Null | Tree Label Tree Tree deriving (Eq,Show)
type Label = Integer
但在我的例子樹心不是空還是什麼?
tcm :: (Label -> Label) -> Tree -> Tree
tzp :: (Label -> Label -> Label) -> Tree -> Tree -> Tree
tcm (+1) t1 == Null
tcm (+1) t2 == Tree 3 (Tree 4 Null Null) (Tree 6 Null Null)
tcm (+1) t3 == Tree 3 (Tree 4 (Tree 6 Null Null) Null) (Tree 8 Null Null)
tzp (+) t1 t2 == Null
tzp (+) t2 t3 == Tree 4 (Tree 6 Null Null) (Tree 12 Null Null)
有人可以幫我用這些函數和樹嗎?