Ocaml Error Unbound Value when using Recursion

19,578

You need to say

let rec count_help ...

to allow the name count_help to be used recursively within its definition.

Share:
19,578
user2823747
Author by

user2823747

Updated on July 12, 2022

Comments

  • user2823747
    user2823747 almost 2 years

    My code is very basic as I am pretty new to ocaml I am trying to call a function recursively but I am getting an unbound value error message on the name of the function

    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
    ;;
    

    The error is Unbound value count_help on the line that calls count_help inside of count_help

    This code is simply suppose to count the number times an association appears for the given character x