在以下方法中,我在if表达式中尝试调用isSample时收到以下错误:error FS0001: This expression was expected to have type bool but here has type Outcome list * ProbTree -> bool
。我不知道为什么收到这条消息。
isSample(os,t)目前属于'a * 'b -> Outcome list * ProbTree -> bool
类型。有任何想法吗?我不明白为什么它突然期望bool
类型。
let rec isSample(os, t) = function
| ([], Branch(_, p, b1, b2)) -> false
| (os, Branch(_, p, b1, b2)) when List.length os = 1 -> true
| (h::t, Branch(_, p, b1, b2)) ->
if h = S then isSample(t, b1) else isSample(t, b2) //This is where I get the error
| _ -> false
type Outcome = | S | F
type Sample = Outcome list
type ProbTree = | Branch of string * float * ProbTree * ProbTree
| Leaf of string