Version française
Home     About     Download     Resources     Contact us    

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

Browse thread
[Caml-list] why the "rec" in "let rec"?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Chris Uzdavinis <chris@a...>
Subject: Re: [Caml-list] why the "rec" in "let rec"?
Garry Hodgson <> writes:

> something i was always curious about: why do you need to specify the
> "rec" in a "let rec" function definition?  as opposed to, say,
> having the compiler figure out when a function is recursive?
> is it a compiler/grammar optimization?  or to help the user, forcing
> them to be precise with recursion?  or required by the type system?

It affects the name lookup rules.  For example:

  let f x = x
  let f x = f x

The 2nd definition for function f is not an infinite loop.  It calls
the previously defined version of f, and is thus a more expensive
identity function.  However:

  let f x = x
  let rec f x = f x

Now the first function is not used by the second (which, due to the
"rec" having been added, is now an infinite loop calling itself.)

> do other ML's do it this way?



To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: