2

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

1 Answer 1

9

You need to say

let rec count_help ...

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.