OCaml Unbound value enf

1.5k views Asked by At

I have a question about using a local function in a global function.
I tried to write the function which appears in the picture, but an error said

unbound value of f

It's strange that this error occurs. It should not appear because I defined the definition of the function enf in affichage.

Here is a picture of a relevant part of my code:

click here to see the picture of program

What can be the reason of this error?

1

There are 1 answers

1
Kevin Ji On

enf is not defined when affichage is defined, so since the body of affichage refers to enf, this results in an unbound value error. In order to have mutually recursive functions, you'll need something of the form

let rec affichage (* ... *) =
  (* ... *)
and enf (* ... *) =
  (* ... *)
in
  (* ... *)
;;