【发布时间】:2011-11-28 11:47:14
【问题描述】:
我正在尝试制作一个 OCaml 函数,它将字符串中的 'a' 的数量添加到给定的参数中。
let rec count_l_in_word (initial : int) (word : string) : int=
if String.length word = 0 then initial else
if word.[0] = 'a' then
count_l_in_word initial+1 (Str.string_after word 1)
else count_l_in_word initial (Str.string_after word 1)
我在第 4 行收到一条错误消息,提示“此表达式的类型为 string -> int 但此处与 int 类型一起使用”。我不知道为什么它期望表达式'count_l_in_word initial+1'是一个int。它真的应该期望整行 'count_l_in_word initial+1 (Str.string_after word 1)' 是一个 int。
谁能帮忙解决这个问题
【问题讨论】:
标签: functional-programming ocaml currying