Version française
Home     About     Download     Resources     Contact us    
Browse thread
Simple factorial
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: robert@f...
Subject: Re: [Caml-list] Simple factorial
> I've just started learning O'Caml. I've written a simple factorial
> function (no checking whether n is 1 etc.):
>
> let rec factorial n =
> 	n * factorial (n-1);;
>
> When I call this function with let's say 5 as an argument, I get an
> overflow error message.
>
> Any ideas?
>
You haven't defined a stop condition, so it's going down and down into the
negatives until it overflows.

~~ Robert.