Functions calling each other in a module in OCaml

I have a question about ocaml, I'm a newbie :-)

Here's an example of what I'm trying to do: (I know this doesn't make sense, but this is not my real code, this is just an example)

let func a b = a
let func2 a b = b

let func_a a b =
    if b < 0 then
       func_b b a
    else
       func a b

let func_b a b =
    if a < 0 then
       func2 a b
    else
       func_a b a

      

The problem is this: Unbound value func_b in the first "if" in func_a...

If anyone can help?

Edit: I understand why this is unrelated, but I don't know how to fix it.

Thank you so much!

Max

+3


source to share


1 answer


Keyword mutually recursive functions :



let func a b = a
let func2 a b = b

let rec func_a a b =
    if b < 0 then
       func_b b a
    else
       func a b

and func_b a b =
    if a < 0 then
       func2 a b
    else
       func_a b a

      

+5


source







All Articles