caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Basile Starynkevitch <basile@starynkevitch.net>
To: Jean-Baptiste Jeannin <jeannin@cs.cornell.edu>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Cyclic data structures: internal representation
Date: Mon, 12 Nov 2012 09:55:26 +0100	[thread overview]
Message-ID: <20121112085526.GA31519@ours.starynkevitch.net> (raw)
In-Reply-To: <A7FC6DE86AF33142A1FA4CE04EEBF4F18596A9DD62@gobo.cs.cornell.edu>

On Mon, Nov 12, 2012 at 01:44:55AM -0500, Jean-Baptiste Jeannin wrote:
> Good morning,
> 
> One can create cyclic data structures in OCaml, using the keyword let rec. For example:
> 
>   # let rec l0 = 1 :: 2 :: l0;;
>   var l0 : int list =
>     [1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; 1; 2; ...]
> 
> I am wondering what the internal representation (in the AST) of such a data structure is. 

It is related to the notion of statically constructive expressions, see section 7.3 of the ocaml manual
http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual021.html

statically constructive expressions (which *exclude* function applications, and  conditionals) can be first constructed (as yet-unfilled values) then filled. In that case, the compiler emit first the code for all the constructions, then the code for all the filling (taking into account the recursively bound variables).

This is not Ocaml specific; any Lisp or Scheme (or related, e.g. http://gcc-melt.org/ for example) 
language also do that to implement let-rec kind of mutually recursive definitions.

A very good explanation about that happens in Christian Queinnec "Lisp In Small Pieces" books. 
If you read french, you could read the latest variant in Franch on 
http://paracamplus.com/?CGIRunMode=book&urn=Cours/LiSP/4 
Principes d'implantation de Scheme et Lisp 
ISBN 	978-2-916466-03-3

Regards
-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***

  reply	other threads:[~2012-11-12  8:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-12  6:44 Jean-Baptiste Jeannin
2012-11-12  8:55 ` Basile Starynkevitch [this message]
2012-11-12  9:43 ` Gabriel Scherer
2012-11-12 11:24 ` Dmitry Grebeniuk

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=20121112085526.GA31519@ours.starynkevitch.net \
    --to=basile@starynkevitch.net \
    --cc=caml-list@inria.fr \
    --cc=jeannin@cs.cornell.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;
as well as URLs for NNTP newsgroup(s).