我很努力去理解這一點。問題:SML類型 - >類型 - >類型
我
datatype 'a tree= Leaf of 'a | Node of 'a tree * 'a * 'a tree
我必須找到使用二進制搜索它的價值。這是我的代碼。
fun binSearch ((Leaf n), x) = if n=x then true else false
| binSearch ((Node (left, n, right)), x) =
if n=x then true else
if n>x then binSearch (left, x) else
binSearch (right, x)
但我應該寫函數與此簽名:
val binSearch : int tree -> int -> bool
我得到的int tree * int -> bool
一部分,但我該怎麼做'a -> 'b -> 'c
駕車評論:「如果C然後真的別的假」是一種複雜的寫作'C'的方式。 ;)同樣,「如果C正確,否則E'只是'C orelse E'。 – 2015-04-02 07:32:01
@AndreasRossberg所以如果我得到這個權利'1 = 1 orelse false'返回true,'1 = 2 orelse false'返回false。如果我寫代碼而不是'false'會怎麼樣? – Whazz 2015-04-02 19:57:51
'C orelse false'與'C'返回一樣,所以你不會寫這個。 'C1 orelse C2'是'如果C1然後是真的別的C2'的簡稱。同樣,'C1和C2'也是'如果C1然後C2否則爲假'的簡稱。與C中的'||'和'&&'相同 – 2015-04-03 07:18:03