The short answer is that you're misusing root
. It's NthRoot.root
, from src/HOL/NthRoot.thy
, and the type of root
is shown in the error message:
root :: nat => real => real
I CNTL-clicked on root
, and it took me to the function in NthRoot.thy
.
From here, I basically complain that you made me work harder than I wanted, to answer your question, and even now, I'm assuming that I made me a THY which is duplicating what you're talking about.
You gave me this phrase in your comment: "imports Main Tree". However, after making a THY using only Main
, the THY is obviously not what you're doing, because I don't get the error message 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
Also, in that THY, root
is not defined, it's a variable. I saw that in two ways. I tried to CNTL-click on it, and nothing happened. I then noticed that it's blue, which means it's a local variable.
So, I imported Complex_Main
like the following, and I got the error message that you're talking about. I know nothing much about binary trees, but the type of root
shown in the error message can quickly tell you that root
is most likely not what you want, since it's using 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
Anyway, people don't want to see too much source in questions, and they don't want to see too little. If you provide the magic amount, and all they have to do is cut and paste, then they don't have to work as hard to answer your question.
From your last question, Predefined functions for Binary trees in Isabelle, I knew where to get Tree
from what Andreas said.
Andreas is the answer man for people like me and you. If you want to increase the chances of someone like him answering questions, then you want him to have to work as little as possible to figure out your question.
A minimal working example can help make sure everyone is on the same page, and even catch some mistakes on your end before you ask a question.