caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Martin Jambon <martin.jambon@ens-lyon.org>
Cc: Lukasz Stafiniak <lukstafi@gmail.com>,
	Diego Olivier Fernandez Pons <dofp.ocaml@gmail.com>,
	caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Examples where let rec is undesirable
Date: Tue, 3 Jan 2012 09:07:43 +0100	[thread overview]
Message-ID: <CAPFanBHDVny-XnB=tNL4vXfDYOtBEa0_k08cCtgLAZCZ8-Bw1A@mail.gmail.com> (raw)
In-Reply-To: <4F02967A.7060303@ens-lyon.org>

> What I am wondering is why type definitions are recursive by default. It
> is mostly troubling for beginners.

Indeed, it is a defect of the language not to have non-recursive type
definitions. My usual reference on this topic is Yaron's complaint:
  https://ocaml.janestreet.com/?q=node/25

The problem is not so much that they are "recursive by default" (I
believe this would be justified by the relative frequencies of
recursive type definitions and type-level name recycling) but that
they *must* be recursive. It would be better to have some kind of
"type-nonrec" construct for non-recursive type declarations.

This is however a case were it is difficult to fix the issue in a
fully convenient way: you don't want to add a new keyword, you
certainly don't want to change the behavior of existing "type"
declarations, and all solutions remaining are likely to be convoluted
and feel like a ad-hoc patch.
Given there is the reasonable (if ugly) workaround of breaking the
cycle through an auxiliary type renaming, there are few incentives to
change the state of the art. I believe this is something you could and
should easily fix when designing a new language (when introducing
*any* binding construct, think about both a recursive (when it makes
sense) and a non-recursive version), but that may have to stay with us
for OCaml.

On Tue, Jan 3, 2012 at 6:47 AM, Martin Jambon
<martin.jambon@ens-lyon.org> wrote:
> On 01/02/2012 04:05 PM, Lukasz Stafiniak wrote:
>> On Mon, Jan 2, 2012 at 11: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
>>
>> The default "no-rec" allows for name recycling -- using the same name
>> for an incrementally transformed value, i.e. to bind the intermediate
>> results. Name recycling minimizes the cognitive burden: there are less
>> names to remember in a scope, and differences in names are justified
>> by differences in purpose of the values. Are there reasons to consider
>> name recycling a bad style?
>
> What I am wondering is why type definitions are recursive by default. It
> is mostly troubling for beginners.
>
> The following is an occasional inconvenience of having only recursive
> type definitions:
>
> module A =
> struct
>  type t = ...
>  let compare = ...
>
>  module B =
>  struct
>    type t = t (* uh oh *)
>    let compare = compare
>  end
> end
>
>
> Martin
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2012-01-03  8:08 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
2012-01-03  0:05 ` Lukasz Stafiniak
2012-01-03  5:47   ` Martin Jambon
2012-01-03  8:07     ` Gabriel Scherer [this message]
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='CAPFanBHDVny-XnB=tNL4vXfDYOtBEa0_k08cCtgLAZCZ8-Bw1A@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=dofp.ocaml@gmail.com \
    --cc=lukstafi@gmail.com \
    --cc=martin.jambon@ens-lyon.org \
    /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).