我的代码非常基本,因为我对ocaml很新 我试图以递归方式调用函数,但我在函数名称上收到未绑定的值错误消息
let count_help x a lst = match lst with
[] -> a
| (s,i)::t -> if s = x then count_help x a+1 t else count_help x a t
;;
let count_assoc lst x =
count_help x 0 lst
;;
错误是在count_help内调用count_help的行上的未绑定值count_help
此代码简单地假设计算给定字符x
的关联出现的次数答案 0 :(得分:8)
你需要说
let rec count_help ...
允许在其定义中递归使用名称count_help
。