caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alexandre Pilkiewicz <alexandre.pilkiewicz@polytechnique.org>
To: Diego Olivier Fernandez Pons <dofp.ocaml@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Examples where let rec is undesirable
Date: Mon, 2 Jan 2012 17:49:59 -0500	[thread overview]
Message-ID: <CAH2fdNYT3QvgB_pAObui250tEmgZz0ccLJyyZOyTAarHx5ps7w@mail.gmail.com> (raw)
In-Reply-To: <CAHqiZ-LhsBa4Xn51dCDAeOpTVMzF8kJCestAGydh5abMHsOidQ@mail.gmail.com>

Hi Diego.

I think one of the best reason to *not* have let rec as the default is
shadowing.

Say you have a function that expect a string as an argument

let foo s =
  ....
  ....

and you realize that it's the job of the callee and not the caller to
check that the string is escaped. You can just change it to:

let foo s =
  let s = escape s in
  ....
  ....

And before you say "let's just do this for function and not for other
values", let's remember that nothing separate a function from a value
syntactically (it's a functional language, a function *is* a value),
only typing can. And you can't type your program before you know its
structure, and let vs let rec is part of the structure.

Then on top of that we can add that it makes compilation faster,
optimization easier, and code clearer (and, of course, backward
compatibility :))!

Cheers

Alexandre


On Mon, Jan 2, 2012 at 5:37 PM, Diego Olivier Fernandez Pons
<dofp.ocaml@gmail.com> wrote:
>     List,
>
> I was wondering if there was any reason not to make "let rec" the default /
> sole option, meaning cases where you clearly don't want a "let rec" instead
> of "let" (only in functions, not cyclic data).
>
>          Diego Olivier


  reply	other threads:[~2012-01-02 22:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-02 22:37 Diego Olivier Fernandez Pons
2012-01-02 22:49 ` Alexandre Pilkiewicz [this message]
2012-01-03  0:05 ` Lukasz Stafiniak
2012-01-03  5:47   ` Martin Jambon
2012-01-03  8:07     ` Gabriel Scherer
2012-01-05 20:04   ` Richard W.M. Jones
2012-01-05 20:27     ` ivan chollet
2012-01-05 20:46       ` Gabriel Scherer
2012-01-05 21:39         ` Richard W.M. Jones
2012-01-06  2:39           ` Cedric Cellier
2012-01-06 15:22         ` Damien Doligez
2012-01-05 21:36       ` Richard W.M. Jones
2012-01-05 23:16         ` ivan chollet
2012-01-06  8:34           ` David Allsopp
2012-01-06 10:34           ` Daniel Bünzli
2012-01-03 13:05 ` Yaron Minsky

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=CAH2fdNYT3QvgB_pAObui250tEmgZz0ccLJyyZOyTAarHx5ps7w@mail.gmail.com \
    --to=alexandre.pilkiewicz@polytechnique.org \
    --cc=caml-list@inria.fr \
    --cc=dofp.ocaml@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).