Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ocaml Error Unbound Value when using Recursion

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

like image 695
user2823747 Avatar asked Jun 12 '26 22:06

user2823747


1 Answers

You need to say

let rec count_help ...

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

like image 153
Jeffrey Scofield Avatar answered Jun 14 '26 15:06

Jeffrey Scofield