2

I defined these two functions in F#

let f t = 
   match t with
   |_ when t = 0 -> 1
   |_ -> g t-1

let g t = 1 + (f t)

However, F# compiler didn't accept it. It said that

stdin(9,16): error FS0039: The value or constructor 'f' is not defined

Please help me! Thanks.

MisterMetaphor
  • 5,900
  • 3
  • 24
  • 31
  • 1
    Also, if you pasted just that into a blank `fsi` you will get a message about `g` being undefined. It is good to show the correct error message by starting a new `fsi` and rerunning all your code to ensure nothing is left from previous experiments – John Palmer Sep 02 '13 at 10:47

1 Answers1

5

F# supports mutual recusion using the let rec ... and ... syntax. Here is your example

let rec f t = 
   match t with
   |_ when t = 0 -> 1
   |_ -> g t-1

and g t = 1 + (f t)
John Palmer
  • 25,356
  • 3
  • 48
  • 67