Functional programming OCaml表达式类型问题

Functional programming OCaml表达式类型问题,functional-programming,ocaml,currying,Functional Programming,Ocaml,Currying,我试图创建一个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

我试图创建一个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_in word 1后)”是int

有人能帮忙吗

count_l_in_word initial+1 (Str.string_after word 1)
被解析为

(count_l_in_word initial) + (1 ((Str.string_after word) 1))
因此,您需要添加一些参数:

count_l_in_word (initial + 1) (Str.string_after word 1)

谢谢,我想我得小心点。我得到了它的工作,虽然规则IIRC是函数应用程序比任何操作符都有更高的优先级。这在FP语言中很常见。它不是被解析为
(count\u l\u in\u word initial)+(1((Str.string\u在单词后)1))
?@newacct:你说得对。我没有想到解析器会生成一个函数应用程序,函数为
1