[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | William D. Neumann <wneumann@c...> |
| Subject: | Re: [Caml-list] Factorial function |
On Tue, 23 Jan 2007, Lucas Holland wrote:
> Hi, why does this function:
>
> let rec fact n =
> n * fact (n-1);;
>
> yield an overflow error if called with n = 5?
It overflows because you don't provide a base case for the recursion (e.g.
if n = 1 then 1 else ...), it simply cycles backwards through the ints
until the stack is exhausted.
Also, if you're just learning OCaml, you may want to use the Caml
Beginners list for these types of questions. You con find the list
information at: http://groups.yahoo.com/group/ocaml_beginners
William D. Neumann
---
"There's just so many extra children, we could just feed the
children to these tigers. We don't need them, we're not doing
anything with them.
Tigers are noble and sleek; children are loud and messy."
-- Neko Case
Life is unfair. Kill yourself or get over it.
-- Black Box Recorder