i think function language must be can coding tail recursion..

By on 5/19/2010 7:04 AM ()

F# can do tail recursion.

Your implementation, however is NOT T.R. (the multiplication is done after the recursion).

This TR implementation works:

1
2
3
4
5
6
7
8
9
10
11
12
let rec factorial n = 

	let rec loop acc i =

		if i > n then acc

		else loop (acc*i) (i+1I)

	loop 1I 1I

factorial 1100I;;

The "I" is the literal suffix for big integers.

Sorry for the formatting. IE sux.

By on 5/19/2010 7:17 AM ()

thanks a lot ,i got it.:)

By on 5/19/2010 7:41 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