3
我必須做一個遞歸函數來計算三種不同類型的二叉樹的節點數,並且我將它們保存在下面的類型爲int * int * int的結果中,我想我的推理是正確的。OCaml未綁定值
type dtree =
Decision of string * int * dtree * string * int * dtree
| Chance of string * int * dtree * string * int * dtree
| Outcome of int
;;
let rec count dt =
match dt with
Decision(choiceL, costL, l, choiceR, costR, r) -> (x+1,y,z) count l count r
| Chance(eventL, probL, l, eventR, probR, r) -> (x,y+1,z) count l count r
| Outcome value -> (x,y,z+1)
;;
如何在指定的函數中定義變量? – MMrj
使用'let'給一個名字(或多個名字)給你的遞歸調用返回的值。 –