簡短的回答是,你濫用root
。這是NthRoot.root
,從src/HOL/NthRoot.thy
,並root
該類型是在錯誤信息中顯示:
root :: nat => real => real
我CNTL-點擊root
,它帶我去功能NthRoot.thy
。
從這裏,我基本上抱怨說,你讓我比我想要的更努力,回答你的問題,甚至現在,我假設我讓我變成了你正在談論的重複內容。
你在評論中給了我這句話:「進口主樹」。但是,在THY僅使用Main
之後,THY顯然不是您正在做的,因爲我沒有收到錯誤消息Type unification failed: Clash of types "bst" and "nat"
。
theory Scratch
imports Main "~~/src/HOL/Library/Tree"
begin
datatype bst = Leaf | Node int bst bst
fun lookup :: "int ⇒ bst ⇒ bool" where
"lookup x _ = false" |
"lookup x bst = (if x = root(bst) then true else if x ≤ root(bst)
then lookup x left(bst) else lookup x right(bst))"
end
此外,在THY中,root
沒有定義,它是一個變量。我以兩種方式看到了這一點。我試圖讓CNTL點擊它,但什麼都沒發生。然後我注意到它是藍色的,這意味着它是一個局部變量。
因此,我導入了Complex_Main
,如下所示,並且我收到了您所說的錯誤消息。我對二叉樹一無所知,但錯誤消息中顯示的root
類型可以很快告訴您,root
很可能不是您想要的,因爲它使用的是real
。
theory Scratch2
imports Complex_Main
begin
datatype bst = Leaf | Node int bst bst
fun lookup :: "int => bst => bool" where
"lookup x _ = false" |
"lookup x bst = (if x = root(bst) then true else if x ≤ root(bst)
then lookup x left(bst) else lookup x right(bst))"
(*Type unification failed: Clash of types "bst" and "nat"
Type error in application: incompatible operand type
Operator: root :: nat => real => real*)
end
無論如何,人們不想看到太多的問題來源,他們不想看到太少。如果你提供魔術數量,而他們所要做的只是剪切和粘貼,那麼他們不需要努力回答你的問題。
從你上一個問題,Predefined functions for Binary trees in Isabelle,我知道從Andreas說什麼Tree
。
安德烈亞斯是像我和你這樣的人的答案。如果你想增加像他這樣的人回答問題的機會,那麼你希望他必須儘可能少地工作以找出你的問題。
一個最簡單的工作示例可以幫助確保每個人都在同一頁面上,甚至在提出問題之前在您的結尾處發現一些錯誤。
'root','left'和'right'的類型是什麼? – 2014-10-27 14:54:33
順便說一句,函數總是返回'false',因爲第一個模式總是匹配。 – 2014-10-27 14:56:51
你應該展示一個THY的完整工作示例,除其他外,它將顯示'imports'。你在那裏使用4個函數,'root','lookup','left'和'right'。如果他們是你自己的,那麼人們需要知道類型。如果他們來自src/HOL,那麼'Complex_Main'中有很多人不使用,或者在圖書館中THYs中人們不會導入,使用甚至不知道。 – 2014-10-27 15:14:08