From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id DAA5E7EE20 for ; Mon, 12 Nov 2012 09:55:34 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of basile@starynkevitch.net) identity=pra; client-ip=195.14.0.142; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="basile@starynkevitch.net"; x-sender="basile@starynkevitch.net"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of basile@starynkevitch.net) identity=mailfrom; client-ip=195.14.0.142; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="basile@starynkevitch.net"; x-sender="basile@starynkevitch.net"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@de558.ispfr.net) identity=helo; client-ip=195.14.0.142; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="basile@starynkevitch.net"; x-sender="postmaster@de558.ispfr.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvoHABm3oFDDDgCO/2dsb2JhbABEDotgt2eBCYIeAQEFOhwjEAsYFRkUJSSIIQe6WIwVgxeCUmEDlXsBgRyKGYUOgjI+gWMX X-IronPort-AV: E=Sophos;i="4.80,761,1344204000"; d="scan'208";a="162122415" Received: from 195-14-0-142.nuxit.net (HELO de558.ispfr.net) ([195.14.0.142]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 12 Nov 2012 09:55:34 +0100 Received: from ours.starynkevitch.net ([213.41.244.95] helo=hector.lesours) by de558.ispfr.net with esmtp (Exim 4.72) (envelope-from ) id 1TXpno-0005JI-9X; Mon, 12 Nov 2012 09:55:32 +0100 Received: from basile18 by hector.lesours with local (Exim 4.80) (envelope-from ) id 1TXpni-0008Cs-Oe; Mon, 12 Nov 2012 09:55:26 +0100 Date: Mon, 12 Nov 2012 09:55:26 +0100 From: Basile Starynkevitch To: Jean-Baptiste Jeannin Cc: "caml-list@inria.fr" Message-ID: <20121112085526.GA31519@ours.starynkevitch.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [Caml-list] Cyclic data structures: internal representation 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: basilestarynkevitchnet mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} ***