Hi, The solution for your problem is to fix the spelling error. :)
Just replace >= 1 with <= 1 and it will work. By definition, factorial(0) is 1.

You can also handle the < 0 case and raise an exception.

Laurent

By on 11/5/2008 11:30 AM ()

| _ when n >= 1 -> 1

Actually, this should return 1 and not involve a stack at all.

By on 11/5/2008 11:03 AM ()

Hi,
I'm afraid there is really no way to catch this exception.
The solution for this specific problem is to use "tail-recursion" - this means that you can rewrite the code in a way that it is still recursive, but it doesn't take any space on the stack. This is discussed in Expert F# in chapter 8 around page 199, so you may want to check this part of the book.

T.

By on 11/5/2008 3:09 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