To define mutually recursive functions, use "let rec x ... and y ..." - the key is changing the second "let" to "and".

By on 11/30/2008 9:56 PM ()

Does F# support tail call optimization in this case(mutually recursive functions) ?

By on 12/1/2008 1:12 AM ()

Yes; the F# compiler will often turn a directly recursive function into a loop, but all tail calls are emitted with the .tail IL instruction, so code like the above will not stack overflow. (Try it:

1
2
3
4
5
6
7
8
9
10
#light

let rec even n =
    if n = 0 then true
    else odd (n-1)
and odd n =
    if n = 0 then false
    else even (n-1)

printfn "%A" (even 1000000)

)

By on 12/1/2008 1:28 AM ()

Thank you very much

it worked!!

By on 12/1/2008 12:35 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper