2

Possible Duplicate:
How to have two methods calling each other?

I need to write 2 functions that call each other. (with conditions inside - so they'd eventually stop)

let x () : int =
   ...
   if (------) then
     y num
   ...


let y () : int =
   ...
   if (------) then
     x num
   ...

The problem is that, as I understand it, F# evaluates functions by order of appearance.. so writing this will create compilation errors...

Is there a way to solve this problem? So both functions will know each other?

Community
  • 1
  • 1
cookya
  • 3,019
  • 7
  • 26
  • 37

1 Answers1

7

You need the and keyword for mutually-recursive functions:

let rec x num =
   ...
   if (------) then
     y num
   ...

and y num =
   ...
   if (------) then
     x num
   ...
pad
  • 41,040
  • 7
  • 92
  • 166