I am trying to make an OCaml function that addsthe number of ‘a’s in a string to a given argument.
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)
I get an error on line 4 saying ‘This expression has type string -> int but is here used with type int’. I am not sure why it expects the expression ‘count_l_in_word initial+1’ to be an int. It should really expect the whole line ‘count_l_in_word initial+1 (Str.string_after word 1)’ to be an int.
Can anyone help with this
is parsed as
so you need to add some parens: