Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Pierre Weis <pierre.weis@inria.fr>
To: info@gerd-stolpmann.de (Gerd Stolpmann)
Cc: hdaume@ISI.EDU, neelk@alum.mit.edu, caml-list@inria.fr
Subject: Re: [Caml-list] why the "rec" in "let rec"?
Date: Tue, 13 May 2003 18:36:05 +0200 (MET DST)	[thread overview]
Message-ID: <200305131636.SAA10869@pauillac.inria.fr> (raw)
In-Reply-To: <1052323141.16633.108.camel@ares> from Gerd Stolpmann at "May 7, 103 05:59:01 pm"

[...]
> To summarize, the difference between "let" and "let rec" is that they
> are based on theories with different strengths, and the language
> designers don't want to unify such constructs (IMHO, a good attitude).
> 
> Gerd
> -- 
> ------------------------------------------------------------
> Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
> gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
> ------------------------------------------------------------

An important additional advantage of identifier rebinding
is to avoid confusion between the new and old value: the rebinding makes
it explicit that the old value is now irrelevant and the language
scoping rules will then ensure this property.

For example, consider the following (pseudo)-code snippet where we
carefully avoid rebinding of i, using a new name j instead:

 ... i ...
 let j = i + 1 in
 ... j ...         (* 3 *)

In these circumstances, the programmer can confuse i and j, using i
instead of j in part (* 3 *). Since, unfortunately, i and j have the
same type, the compiler can not detect this error. By contrast,
rebinding i elegantly avoids this problem:

 ... i ...
 let i = i + 1 in  (* 2 *)
 ... i ...         (* 3 *)

after (* 2 *) the old value of i is lost (no more accessible) and the
code is thus clearer and more robust in my opinion.

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      reply	other threads:[~2003-05-13 16:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-07 14:04 Garry Hodgson
2003-05-07 14:31 ` Chris Uzdavinis
2003-05-07 14:50 ` Neel Krishnaswami
2003-05-07 14:57   ` Hal Daume III
2003-05-07 15:11     ` Falk Hueffner
2003-05-07 15:16     ` David Brown
2003-05-07 15:53       ` Brian Hurt
2003-05-07 15:51         ` Garry Hodgson
2003-05-07 15:40     ` Neel Krishnaswami
2003-05-07 15:59     ` Gerd Stolpmann
2003-05-13 16:36       ` Pierre Weis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200305131636.SAA10869@pauillac.inria.fr \
    --to=pierre.weis@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=hdaume@ISI.EDU \
    --cc=info@gerd-stolpmann.de \
    --cc=neelk@alum.mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox