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'给一个名字(或多个名字)给你的递归调用返回的值。 –