This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Difference between "let rec" and just "let"?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2008-08-13 (13:52) From: Jean Krivine Subject: Re: [Caml-list] Difference between "let rec" and just "let"?
```Each time you use let, you can also use let rec, but you have to use
the rec (for recursive) if you want to declare a recursive function as
in:
let rec f x = if x<0 then 0 else x * f(x-1)

On Wed, Aug 13, 2008 at 8:49 AM, circ ular <circularfunc@gmail.com> wrote:
> what is the difference between "let rec" and just "let"? what does rec
> stand for?
>
> are the following defintions exactly the same? at least they seem to
> give the same results...
>
> # let rec cube x = x*x*x;;
> val cube : int -> int = <fun>
> # cube 12;;
> - : int = 1728
>
> # let cubex x = x*x*x;;
> val cubex : int -> int = <fun>
> # cubex 12;;
> - : int = 1728
> #
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

```