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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 514E77F2AA for ; Tue, 18 Dec 2012 09:37:51 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of eric.jaeger@ssi.gouv.fr) identity=pra; client-ip=86.65.182.16; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="eric.jaeger@ssi.gouv.fr"; x-sender="eric.jaeger@ssi.gouv.fr"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of eric.jaeger@ssi.gouv.fr) identity=mailfrom; client-ip=86.65.182.16; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="eric.jaeger@ssi.gouv.fr"; x-sender="eric.jaeger@ssi.gouv.fr"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp.ssi.gouv.fr) identity=helo; client-ip=86.65.182.16; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="eric.jaeger@ssi.gouv.fr"; x-sender="postmaster@smtp.ssi.gouv.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8EAGAq0FBWQbYQ/2dsb2JhbABEgkm7XhZzgiUIAh0BBTEoBWg/AQQeBYgHmFKREZBFjWuDKQOILIVRjWWKcIJ0 X-IronPort-AV: E=Sophos;i="4.84,308,1355094000"; d="scan'208,217";a="186613053" Received: from smtp.ssi.gouv.fr ([86.65.182.16]) by mail1-smtp-roc.national.inria.fr with ESMTP; 18 Dec 2012 09:37:50 +0100 Received: from smtp-switch.internet.local (smtp-switch [192.168.3.9]) by smtp.ssi.gouv.fr (Postfix) with ESMTP id 3F1FF90B97F for ; Tue, 18 Dec 2012 09:37:50 +0100 (CET) From: "Eric Jaeger" To: Date: Tue, 18 Dec 2012 09:37:49 +0100 Message-ID: <003801cddcfa$f66325c0$e3297140$@jaeger@ssi.gouv.fr> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0039_01CDDD03.58278DC0" X-Mailer: Microsoft Outlook Thread-Index: Ac3c+vX/tIi4mSRoSeaiY8eS00MPkw== Content-Language: fr Subject: [Caml-list] Function returning recursive lists This is a multi-part message in MIME format. ------=_NextPart_000_0039_01CDDD03.58278DC0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi everyone, =20 There are various discussions on recursive lists in the archive, yet I was wondering whether or not it was possible in pure OCaml to write a function returning non-constant recursive lists. =20 For example, I would like to have a function =93docycle:=92a list->=92a lis= t=94 that takes a non recursive list and transforms it into a recursive list containing the same elements. That is, =93docycle [1;2;3]=94 would return a= list structurally equivalent to =93let rec c=3D1::2::3::c in c=94. So far, my va= rious attempts (OCaml 3.12) have not been successful. Another good example is to have a List.map compatible with recursive lists. =20 Please note that it is, in a way, a theoretical (and possibly na=EFve) question : - I do not consider recursive lists as the perfect implementation for my problem - I do not care about efficiency - I do not want to use an ad hoc mutable/lazy list datatype (unless I=92ve also a conversion function toward standard lists) - I do not want to use Obj or other similar tricks It=92s just that I=92m curious whether or not what I=92m trying to achieve = is possible. =20 Regards, Eric =20 ------=_NextPart_000_0039_01CDDD03.58278DC0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hi everyone,

=  

There a= re various discussions on recursive lists in the archive, yet I was wonderi= ng whether or not it was possible in pure OCaml to write a function returni= ng non-constant recursive lists.

=  

For example, I would like to have a function “docycle:= 217;a list->’a list” that takes a non recursive list and tra= nsforms it into a recursive list containing the same elements. That is, = 220;docycle [1;2;3]” would return a list structurally equivalent to &= #8220;let rec c=3D1::2::3::c in c”. So far, my various attempts (OCam= l 3.12) have not been successful. Another good example is to have a List.ma= p compatible with recursive lists.

 

Please note that it is, in a way, a theoretical (and possibly= naïve) question :

-          = I do not consider recursi= ve lists as the perfect implementation for my problem

=

-    &= nbsp;     I do not care about efficiency

-       = ;   I do not wa= nt to use an ad hoc mutable/lazy list datatype (unless I’ve also a co= nversion function toward standard lists)

-      &n= bsp;   I do not= want to use Obj or other similar tricks

It’s just that I’m curious whether o= r not what I’m trying to achieve is possible.

 

  Regards, Eric

<= p class=3DMsoNormal> 

= ------=_NextPart_000_0039_01CDDD03.58278DC0-- 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 70D827F2AB for ; Tue, 18 Dec 2012 10:37:01 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.214.47; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.214.47 as permitted sender) identity=mailfrom; client-ip=209.85.214.47; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-bk0-f47.google.com) identity=helo; client-ip=209.85.214.47; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-bk0-f47.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjsBAOA40FDRVdYvk2dsb2JhbABEhXS4KggWDgEBAQEJCQsJFAQjgh4BAQVAARsdAQMMBgULDS4iAREBBQEcBhOIAAEDD5pKjDOBcYEKhRQKGScNWYh2AQUMjEWEQwOWCo5oFimEFQ X-IronPort-AV: E=Sophos;i="4.84,308,1355094000"; d="scan'208";a="186626345" Received: from mail-bk0-f47.google.com ([209.85.214.47]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 18 Dec 2012 10:36:26 +0100 Received: by mail-bk0-f47.google.com with SMTP id j4so159795bkw.20 for ; Tue, 18 Dec 2012 01:36:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=wcQtkV87Xoh0ebVXi56a7wPextDEHJy74yy0gKNY48k=; b=K2bvGTCGmHlhJdp3jWCv0lpx0SLMEck9xKEPRImf9jJ9ljmJ0gCJDS2Kifwe9+9/rm 726tksecoJ58v4dWXTWY6HyNORoJz3wZv8goGAPjJz3D/+/tJo5OwA6JJdaonDoNsqcn 8QgB9IQnsL9FrGBOiK1SLW9prkDokf4HM2aeYjKAVoLRjTeVjcSbr355XAPbWdU1K73t zFqzf4gLIq/HIw4zmtuyDERUMXSlWa99VuAf3JuNekj954JUXytPSQlGcdhjjNYyy02A HGwJB5Khz9sNUdxbDKe4Qla+8FcmT1t+cTJVpSdTIsAku1xEQ8MlIr1C3M/pSKFQUnsW 3oFw== Received: by 10.204.129.66 with SMTP id n2mr450623bks.94.1355823386471; Tue, 18 Dec 2012 01:36:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.204.104.4 with HTTP; Tue, 18 Dec 2012 01:35:46 -0800 (PST) In-Reply-To: <50d02b72.7155c20a.1dbf.4e2fSMTPIN_ADDED_BROKEN@mx.google.com> References: <50d02b72.7155c20a.1dbf.4e2fSMTPIN_ADDED_BROKEN@mx.google.com> From: Gabriel Scherer Date: Tue, 18 Dec 2012 10:35:46 +0100 Message-ID: To: Eric Jaeger Cc: caml-list@inria.fr Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Function returning recursive lists No, I don't think it is. On Tue, Dec 18, 2012 at 9:37 AM, Eric Jaeger wrot= e: > It=92s just that I=92m curious whether or not what I=92m trying to achiev= e is > possible. > > 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 9ED747F2AA for ; Tue, 18 Dec 2012 12:22:01 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of julien.blond@gmail.com) identity=pra; client-ip=209.85.212.43; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="julien.blond@gmail.com"; x-sender="julien.blond@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of julien.blond@gmail.com designates 209.85.212.43 as permitted sender) identity=mailfrom; client-ip=209.85.212.43; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="julien.blond@gmail.com"; x-sender="julien.blond@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-vb0-f43.google.com) identity=helo; client-ip=209.85.212.43; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="julien.blond@gmail.com"; x-sender="postmaster@mail-vb0-f43.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArEBANJQ0FDRVdQrk2dsb2JhbABEvh0IFg4BAQEBCQkLCRQEI4IeAQEEAScZARsdAQMBCwYFCzsiAREBBQEcBhOIAAEDCQaaCowzgXGBCoUdChknDVmIdgEFDJEAA5JXgzOOaBYphBU X-IronPort-AV: E=Sophos;i="4.84,308,1355094000"; d="scan'208";a="166173538" Received: from mail-vb0-f43.google.com ([209.85.212.43]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 18 Dec 2012 12:22:00 +0100 Received: by mail-vb0-f43.google.com with SMTP id fs19so652201vbb.2 for ; Tue, 18 Dec 2012 03:21:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=k92haakHsbhQHHoU8uLcCJwk0FU4CaQOn/cinHgUwSw=; b=pj93ue4sr/5bv9zoh58Ba8ohsXkCG9XDGFwKNZXJAu0ok5xt6JCnSiuzy2kEVR6U8J 6/KHDxFuQusv/Y0zMk5cIqbbNKYwE8s0jwA063A198FLSZob8qOkEqCnoSZsepy4334a 34Gm/VCuQY2ySGPyDL3nrD1+RFa0w/rniTW5AJzhJHLkyGvZAFE72Q471OOK4rJwvfp+ IqHSTcCB191p1zdL60xYaPhUUjLBrvPQUWpNryn3qYY8pO4ICnYiNA8VB38Ezsl+B77p RnhYydACNwSpf5/WJLXehu+51aMNSDef88hhEDCuDcfw4jNqQE2RTZXLeOYdgTw6gRun APMw== MIME-Version: 1.0 Received: by 10.52.178.225 with SMTP id db1mr2132275vdc.10.1355829719467; Tue, 18 Dec 2012 03:21:59 -0800 (PST) Received: by 10.220.115.201 with HTTP; Tue, 18 Dec 2012 03:21:59 -0800 (PST) In-Reply-To: <50d02b65.6c4cb40a.66ab.4256SMTPIN_ADDED_BROKEN@mx.google.com> References: <50d02b65.6c4cb40a.66ab.4256SMTPIN_ADDED_BROKEN@mx.google.com> Date: Tue, 18 Dec 2012 12:21:59 +0100 Message-ID: From: Julien Blond To: Eric Jaeger Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=bcaec5196d71ce061104d11eb441 Subject: Re: [Caml-list] Function returning recursive lists --bcaec5196d71ce061104d11eb441 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Hi Eric, I tried to do something like that some times ago, while my concern was about some tricky recursive module definition, i think the problem was the same : the chicken-egg one. Your docycle is trying to define something it must already know and the problem can't be escaped for evaluation order prevents any value to be recursive at definition time. The recursivity can be achieved by using a second construction pass that corresponds to additional properties (lazyness or mutability or hacking through Obj). Those properties will necessarily occur either explicitly (like OCaml) or implicitly (like in Haskell). So, the real question, as far as i understand your problem, is : are you asking how to hide those properties in OCaml or to see if you need to ask your purchasing department some quantum computer that can predict the address of a future allocated block ? ;) -- Julien 2012/12/18 Eric Jaeger > Hi everyone,**** > > ** ** > > There are various discussions on recursive lists in the archive, yet I was > wondering whether or not it was possible in pure OCaml to write a function > returning non-constant recursive lists.**** > > ** ** > > For example, I would like to have a function =93docycle:=92a list->=92a l= ist=94 > that takes a non recursive list and transforms it into a recursive list > containing the same elements. That is, =93docycle [1;2;3]=94 would return= a > list structurally equivalent to =93let rec c=3D1::2::3::c in c=94. So far= , my > various attempts (OCaml 3.12) have not been successful. Another good > example is to have a List.map compatible with recursive lists.**** > > ** ** > > Please note that it is, in a way, a theoretical (and possibly na=EFve) > question :**** > > **- **I do not consider recursive lists as the perfect > implementation for my problem**** > > **- **I do not care about efficiency**** > > **- **I do not want to use an ad hoc mutable/lazy list datatype > (unless I=92ve also a conversion function toward standard lists)**** > > **- **I do not want to use Obj or other similar tricks**** > > It=92s just that I=92m curious whether or not what I=92m trying to achiev= e is > possible.**** > > ** ** > > Regards, Eric**** > > ** ** > --bcaec5196d71ce061104d11eb441 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable
Hi Eric,

I tried to do something li= ke that some times ago, while my concern was about some tricky recursive mo= dule definition, i think the problem was the same : the chicken-egg one. Yo= ur docycle is trying to define something it must already know and the probl= em can't be escaped for evaluation order prevents any value to be recur= sive at definition time. The recursivity can be achieved by using a second = construction pass that corresponds to additional properties (lazyness or mu= tability or hacking through Obj). Those properties will necessarily occur e= ither explicitly (like OCaml) or implicitly (like in Haskell).

So, the real question, as far as i understand your problem, is : are yo= u asking how to hide those properties in OCaml or to see if you need to ask= your purchasing department some quantum computer that can predict the addr= ess of a future allocated block ? ;)
=A0
-- Julien


2012/12/18 Eric Jaeger <eric.jaeger@ssi.gouv.fr>

Hi everyone,

=A0

There are various discussions on recursive lists i= n the archive, yet I was wondering whether or not it was possible in pure O= Caml to write a function returning non-constant recursive lists.<= /u>

=A0

For example, I would like to have = a function =93docycle:=92a list->=92a list=94 that takes a non recursive= list and transforms it into a recursive list containing the same elements.= That is, =93docycle [1;2;3]=94 would return a list structurally equivalent= to =93let rec c=3D1::2::3::c in c=94. So far, my various attempts (OCaml 3= .12) have not been successful. Another good example is to have a List.map c= ompatible with recursive lists.

=A0

Please note that it is, in a way, = a theoretical (and possibly na=EFve) question :

= -=A0=A0=A0=A0=A0=A0=A0=A0=A0 I do not consider recursive lists as the perfect implement= ation for my problem

-=A0=A0=A0=A0=A0=A0=A0=A0=A0 <= span lang=3D"EN-US">I do not care about efficiency

=

-=A0=A0=A0=A0=A0=A0=A0=A0=A0 <= span lang=3D"EN-US">I do not want to use an ad hoc mutable/lazy list dataty= pe (unless I=92ve also a conversion function toward standard lists)<= u>

-=A0=A0=A0=A0=A0=A0=A0=A0=A0 <= span lang=3D"EN-US">I do not want to use Obj or other similar tricks=

It=92s just that I=92m curious whether or not what I= =92m trying to achieve is possible.

=A0

=A0 Regards, Eric

=A0


--bcaec5196d71ce061104d11eb441-- 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 737A17F2AA for ; Tue, 18 Dec 2012 14:13:45 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of eric.jaeger@ssi.gouv.fr) identity=pra; client-ip=86.65.182.16; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="eric.jaeger@ssi.gouv.fr"; x-sender="eric.jaeger@ssi.gouv.fr"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of eric.jaeger@ssi.gouv.fr) identity=mailfrom; client-ip=86.65.182.16; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="eric.jaeger@ssi.gouv.fr"; x-sender="eric.jaeger@ssi.gouv.fr"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp.ssi.gouv.fr) identity=helo; client-ip=86.65.182.16; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="eric.jaeger@ssi.gouv.fr"; x-sender="postmaster@smtp.ssi.gouv.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8EAMZr0FBWQbYQ/2dsb2JhbABEgkm7XRZzgh8BBQgCHgUxKAMCCUYZPgEBBB4FiAeoE5BQjWODKQONfY1linCCdA X-IronPort-AV: E=Sophos;i="4.84,309,1355094000"; d="scan'208,217";a="186670162" Received: from smtp.ssi.gouv.fr ([86.65.182.16]) by mail1-smtp-roc.national.inria.fr with ESMTP; 18 Dec 2012 14:13:39 +0100 Received: from smtp-switch.internet.local (smtp-switch [192.168.3.9]) by smtp.ssi.gouv.fr (Postfix) with ESMTP id B68B190B97F for ; Tue, 18 Dec 2012 14:13:38 +0100 (CET) From: "Eric Jaeger" To: References: <50d02b65.6c4cb40a.66ab.4256SMTPIN_ADDED_BROKEN@mx.google.com> In-Reply-To: Date: Tue, 18 Dec 2012 14:13:37 +0100 Message-ID: <006701cddd21$7e4235a0$7ac6a0e0$@jaeger@ssi.gouv.fr> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0068_01CDDD29.E0069DA0" X-Mailer: Microsoft Outlook Thread-Index: Ac3dEeiWVpgYwH+TTG+aUhxjz+O/CQADL7WQ Content-Language: fr Subject: RE: [Caml-list] Function returning recursive lists This is a multi-part message in MIME format. ------=_NextPart_000_0068_01CDDD29.E0069DA0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Thanks all for your answers. The consensus seems to be that it is not possible to define an OCaml function returning recursive lists (or more generally recursive values), unless using various forms of tricks such as lazyness or Obj. So on the one hand we have OCaml functions as results of computations which are not analyzable, and on the other hand recursive (immutable) values which are analyzable but can only be defined instead of being computed. I would not request any form of "improvement" in this area (as far as I'm concerned, I'm not comfortable with such recursive values); this was pure curiosity. Regards, Eric ------=_NextPart_000_0068_01CDDD29.E0069DA0 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable

Thanks all for your answers. The consensus seems to be that it is not pos= sible to define an OCaml function returning recursive lists (or more genera= lly recursive values), unless using various forms of tricks such as lazynes= s or Obj. So on the one hand we have OCaml functions as results of computat= ions which are not analyzable, and on the other hand recursive (immutable) = values which are analyzable but can only be defined instead of being comput= ed.

&nbs= p;

I would not req= uest any form of “improvement” in this area (as far as I’= m concerned, I’m not comfortable with such recursive values); this wa= s pure curiosity.

 

&= nbsp; Regards, Eric

 

= ------=_NextPart_000_0068_01CDDD29.E0069DA0-- 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 8AA197F2AA for ; Wed, 19 Dec 2012 17:46:14 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of lukstafi@gmail.com) identity=pra; client-ip=209.85.220.175; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="lukstafi@gmail.com"; x-sender="lukstafi@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of lukstafi@gmail.com designates 209.85.220.175 as permitted sender) identity=mailfrom; client-ip=209.85.220.175; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="lukstafi@gmail.com"; x-sender="lukstafi@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-vc0-f175.google.com) identity=helo; client-ip=209.85.220.175; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="lukstafi@gmail.com"; x-sender="postmaster@mail-vc0-f175.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuwBAIvu0VDRVdyvm2dsb2JhbABEvX8IFg4BAQEBAQgJCwkUJ4IeAQEFQAEbHQEDDAYFCw0uIgERAQUBHAYTiAABAw+ZO4wzgnuFCgoZJw1ZiHYBBQyMQYRDA5YKjmgWKYQW X-IronPort-AV: E=Sophos;i="4.84,318,1355094000"; d="scan'208";a="186899509" Received: from mail-vc0-f175.google.com ([209.85.220.175]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 19 Dec 2012 17:46:13 +0100 Received: by mail-vc0-f175.google.com with SMTP id fy7so2548204vcb.34 for ; Wed, 19 Dec 2012 08:46:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=0E0/qZzrqzUuFnu9V2aM0IgC3+ZhrJMvWWAmZc+7l/U=; b=tVWn/BeEl6Kudi0jFeZBoxO8UdAefy03IIlBcLGvIm3io+l719geCvoqsmXlLHC0gv j1fJPUJTaugtV+V15x6oZouPhB8vseoc+GPpixRQ7NDPjwZkxg6xIg1ik9Gn/jZyomT5 tGUlOD/axR7RJezL42yTtdXzUr1BjJnw38+RoyG1j25LTmiC+HHCnoDw5CtBSw7m9BjG gY99eqDtFqDMdqXIozgPIUpMSwPBrFYdUJ0+u3xV3M4cSod2H89xLV80N7ecExVrxh/x 89C7S8IGR0DWmtqH+HCf3EWClhEbUSdHrU2olv99VijffareAE4XNT8J47F3Z8TJX+TR 17fQ== Received: by 10.52.23.6 with SMTP id i6mr8428605vdf.100.1355935573210; Wed, 19 Dec 2012 08:46:13 -0800 (PST) MIME-Version: 1.0 Received: by 10.58.46.80 with HTTP; Wed, 19 Dec 2012 08:45:52 -0800 (PST) In-Reply-To: <50d06c18.0f5cc20a.16d8.ffff8b8cSMTPIN_ADDED_BROKEN@mx.google.com> References: <50d02b65.6c4cb40a.66ab.4256SMTPIN_ADDED_BROKEN@mx.google.com> <50d06c18.0f5cc20a.16d8.ffff8b8cSMTPIN_ADDED_BROKEN@mx.google.com> From: Lukasz Stafiniak Date: Wed, 19 Dec 2012 17:45:52 +0100 Message-ID: To: Eric Jaeger Cc: Caml Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] Function returning recursive lists On Tue, Dec 18, 2012 at 2:13 PM, Eric Jaeger wrote: > Thanks all for your answers. The consensus seems to be that it is not > possible to define an OCaml function returning recursive lists (or more > generally recursive values), unless using various forms of tricks such as > lazyness or Obj. So on the one hand we have OCaml functions as results of > computations which are not analyzable, and on the other hand recursive > (immutable) values which are analyzable but can only be defined instead of > being computed. The restriction is understandable on semantic basis, e.g. you "want" laziness when you have such recursion. But (1) it can be cumbersome: call-by-value means I need to inline functions / cannot abstract some behaviors into functions; (2) it can give unpleasant surprises, for example when using a state monad hidden behind an abstract data type: the system does not realize that I'm defining a function. 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 D41717F2AA for ; Wed, 19 Dec 2012 23:23:43 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of philippe.wang.lists@gmail.com) identity=pra; client-ip=209.85.219.53; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of philippe.wang.lists@gmail.com designates 209.85.219.53 as permitted sender) identity=mailfrom; client-ip=209.85.219.53; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-oa0-f53.google.com) identity=helo; client-ip=209.85.219.53; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="postmaster@mail-oa0-f53.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArALAIA90lDRVds1m2dsb2JhbABErm+PBggWDgEBAQEBCAkLCRQngh4BAQUnGQE4AQMMAQUFCw0uIhIBBQEcBhOIAQMPmWCPLoUxJw2JTwEFDIxBG4QoA41TiDeOaBYpgVeCP4Fs X-IronPort-AV: E=Sophos;i="4.84,320,1355094000"; d="scan'208";a="166349036" Received: from mail-oa0-f53.google.com ([209.85.219.53]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 19 Dec 2012 23:23:42 +0100 Received: by mail-oa0-f53.google.com with SMTP id j6so2672961oag.26 for ; Wed, 19 Dec 2012 14:23:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=z7kWpLnDlW589DhpEhXpSOKFdN3yIcD4d4CGtQ7E5Ds=; b=TBwUrN4G5BeHya4qz/1VkycuqOKY47A70oYZ3hoGHSy1QYnn3v+4L9Pq9jqBytNOIA Cpr4zK1Si0VuVB3x1ZKUTqHdA67LtAuNrom2iy6iauFFTq6/cffJ8vBLYs1FoOpt8XlI 9BYSP5HochhvW3szMxfVUySMkn1lARDjDPdDWwe2td/fCO+P/4gXcOSmYs55m2Jk8Gy+ vGm9UqFmLO+z4DxKdvjBNNOlzrb3+K39qEVI/vkJ6as0u4UNWNwgRzgW5JLIFbq2w0T8 Q7S3lE8Zhut1fs3p+nanvhVfR6wM8Q+nDO41zMSj4WJtza0pRo/dvTjbXRNiP/1/FimY FAug== MIME-Version: 1.0 Received: by 10.182.8.10 with SMTP id n10mr6311983oba.19.1355955821869; Wed, 19 Dec 2012 14:23:41 -0800 (PST) Sender: philippe.wang.lists@gmail.com Received: by 10.76.86.234 with HTTP; Wed, 19 Dec 2012 14:23:41 -0800 (PST) In-Reply-To: <50d02b62.827bc20a.6f6e.65b8SMTPIN_ADDED_BROKEN@mx.google.com> References: <50d02b62.827bc20a.6f6e.65b8SMTPIN_ADDED_BROKEN@mx.google.com> Date: Wed, 19 Dec 2012 23:23:41 +0100 X-Google-Sender-Auth: iK-x4I1MtHWs_LRHvH0Ckp9Vqmw Message-ID: From: Philippe Wang To: Eric Jaeger Cc: OCaml Mailing List Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Function returning recursive lists Hi, I have a (somehow silly) answer to your question: let gen_make_circ n =3D Printf.printf "let make_circ =3D function [] -> []\n"; for i =3D 1 to n do Printf.printf "| ["; for j =3D i to n do Printf.printf "x%d;" j done; Printf.printf "] -> let rec res =3D "; for j =3D i to n do Printf.printf "x%d :: " j done; Printf.printf "res in res\n" done; Printf.printf "| _ -> failwith \"not implemented\"\n%!" let _ =3D gen_make_circ 4;; prints this : let make_circ =3D function [] -> [] | [x1;x2;x3;x4;] -> let rec res =3D x1 :: x2 :: x3 :: x4 :: res in res | [x2;x3;x4;] -> let rec res =3D x2 :: x3 :: x4 :: res in res | [x3;x4;] -> let rec res =3D x3 :: x4 :: res in res | [x4;] -> let rec res =3D x4 :: res in res | _ -> failwith "not implemented" And then can be used: let _ =3D make_circ [23;45];; - : int list =3D [23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; 45; 23; ...] Cheers, Philippe Wang On Tue, Dec 18, 2012 at 9:37 AM, Eric Jaeger wrot= e: > Hi everyone, > > > > There are various discussions on recursive lists in the archive, yet I was > wondering whether or not it was possible in pure OCaml to write a function > returning non-constant recursive lists. > > > > For example, I would like to have a function =93docycle:=92a list->=92a l= ist=94 that > takes a non recursive list and transforms it into a recursive list > containing the same elements. That is, =93docycle [1;2;3]=94 would return= a list > structurally equivalent to =93let rec c=3D1::2::3::c in c=94. So far, my = various > attempts (OCaml 3.12) have not been successful. Another good example is to > have a List.map compatible with recursive lists. > > > > Please note that it is, in a way, a theoretical (and possibly na=EFve) > question : > > - I do not consider recursive lists as the perfect implementation > for my problem > > - I do not care about efficiency > > - I do not want to use an ad hoc mutable/lazy list datatype (unl= ess > I=92ve also a conversion function toward standard lists) > > - I do not want to use Obj or other similar tricks > > It=92s just that I=92m curious whether or not what I=92m trying to achiev= e is > possible. > > > > Regards, Eric > > --=20 Philippe Wang mail@philippewang.info 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id E52B97F2AA for ; Thu, 20 Dec 2012 00:50:22 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of yallop@gmail.com) identity=pra; client-ip=209.85.212.180; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of yallop@gmail.com designates 209.85.212.180 as permitted sender) identity=mailfrom; client-ip=209.85.212.180; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f180.google.com) identity=helo; client-ip=209.85.212.180; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="postmaster@mail-wi0-f180.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoUBAJxR0lDRVdS0k2dsb2JhbABEhjq3OAgWDgEBAQEJCQsJFAQjgh4BAQUjBBkBGx0BAwwGBQsNAgImAgIiAREBBQEcBhOIAAEDD5lYi2RPgnuFFwoZJw1ZiHYBBQyBFosrG4MVgRMDlgqOaBYphBWBbQ X-IronPort-AV: E=Sophos;i="4.84,320,1355094000"; d="scan'208";a="186937825" Received: from mail-wi0-f180.google.com ([209.85.212.180]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 20 Dec 2012 00:50:22 +0100 Received: by mail-wi0-f180.google.com with SMTP id hj13so1620333wib.13 for ; Wed, 19 Dec 2012 15:50:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=oJnrEkWCM5V1HTn46+rABEAM2YDGI5nvpIxrEMMi8J4=; b=AljWKZJsdAl62tojJWINC8+SxfUS5GEVKa2wYBKOoS971T7o9tn0UNXvgHbf0lsyX/ EN6k+DVxMlAY2G0h2dLt409yr+DdGsp0WNdlqS8A2I85joTIBYkiOOT6E6e5KL/mJoVe T2+V8l1c28jicjHKuiyCWwcEaueocoR64sLL6Tj+uEIZk5XnCSF3IjVmFU/y7/FAbSYg HGA+RS0WD5CBS98EpDgiXHVXm+cBDvHmMAsUhDtUPaaqTBLlD556AXh5Nz7SptftxorE nbg7R11ZqCPVyBUpA5MF+mBsCN/U/rw+LKRLZpCJfCuMBChwRLc+kOyIYjbL1ylIVg7S YWKA== MIME-Version: 1.0 Received: by 10.194.236.68 with SMTP id us4mr14597508wjc.11.1355961022120; Wed, 19 Dec 2012 15:50:22 -0800 (PST) Received: by 10.194.58.101 with HTTP; Wed, 19 Dec 2012 15:50:22 -0800 (PST) In-Reply-To: References: <50d02b62.827bc20a.6f6e.65b8SMTPIN_ADDED_BROKEN@mx.google.com> Date: Wed, 19 Dec 2012 23:50:22 +0000 Message-ID: From: Jeremy Yallop To: Caml List Cc: Eric Jaeger , Philippe Wang Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Function returning recursive lists On 19 December 2012 22:23, Philippe Wang wrote: > I have a (somehow silly) answer to your question: > > let gen_make_circ n = > Printf.printf "let make_circ = function [] -> []\n"; That's an interesting idea, Philippe. Here's an approach along the same lines using MetaOCaml. let rec docycle l = .!(.< let rec s = .~(let rec loop = function | [] -> .< s >. | x :: xs -> .< x :: .~(loop xs) >. in loop l) in s >.) The essential idea is the same as in your code: dynamically generating a suitable 'let rec' expression. However, MetaOCaml also helpfully guarantees that the generated code is well-formed and well-typed, and makes it possible to compile and run the generated code without leaving the language. Here's the code in action: # docycle;; - : 'a list -> 'a list = # docycle [1;2;3];; - : int list = [1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3; 1; ...] # docycle [1;2;3;4;5];; - : int list = [1; 2; 3; 4; 5; 1; 2; 3; 4; 5; 1; 2; 3; 4; 5; 1; 2; 3; 4; ...] (For the sake of simplicity I haven't handled the case where the input list is empty, but that's not difficult to do.) 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 719C07F2AA for ; Thu, 20 Dec 2012 16:24:31 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of agarwal1975@gmail.com) identity=pra; client-ip=209.85.223.177; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="agarwal1975@gmail.com"; x-sender="agarwal1975@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of agarwal1975@gmail.com designates 209.85.223.177 as permitted sender) identity=mailfrom; client-ip=209.85.223.177; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="agarwal1975@gmail.com"; x-sender="agarwal1975@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ie0-f177.google.com) identity=helo; client-ip=209.85.223.177; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="agarwal1975@gmail.com"; x-sender="postmaster@mail-ie0-f177.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvIBAIgs01DRVd+xm2dsb2JhbABEqx+JPgGJCAgWDgEBAQEBCAkLCRQngh4BAQQBJxkBGxILAQMBCwYFBAcNDSEhAQERAQUBChIGExKHbgEDCQYMmjqMM4J7hSMKGScDClmIdgEFDItdaRuEKAOIYotTgVaBHIobgzEWKYQzgU8 X-IronPort-AV: E=Sophos;i="4.84,324,1355094000"; d="scan'208";a="166431108" Received: from mail-ie0-f177.google.com ([209.85.223.177]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 20 Dec 2012 16:24:29 +0100 Received: by mail-ie0-f177.google.com with SMTP id k13so4753852iea.22 for ; Thu, 20 Dec 2012 07:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=w2SwfA/NeoQK/+7wqUzP+Va0ccRV7Iq1C4xrsKGKh48=; b=dGumnHUOByQhHeTCD3JK/+j4gwHxBF3hfeiBauZ1NC1C84XjdJnZjtvH2MlydhcBya HdqA0PTB94qE9J8bzvkxMnhGWGbOlXJ5GdXwljXIqLYnFvToAFLOIuUsfr+f+MgWLO1X jH/nswEyARVL4wYkpJO2UzwFdT8wWbhvwaTbBZXkXDXDqGQZv2tMnXk0AncC57TAo4VB mW9yQ/bx13ZOjAGaWMCsNnxuA5VoBzkL6dvSFG3Kvl+GUT3aD41vmGch017HFKG7rSvg r2tzKU3e85sjX1GzNtpER6EQm9dooF4wFaZDzGOCp74BTwNR0PtoNY5QVFYWCf/75HR8 vIkw== Received: by 10.50.220.199 with SMTP id py7mr10981930igc.34.1356017068616; Thu, 20 Dec 2012 07:24:28 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.47.229 with HTTP; Thu, 20 Dec 2012 07:24:08 -0800 (PST) In-Reply-To: References: <50d02b62.827bc20a.6f6e.65b8SMTPIN_ADDED_BROKEN@mx.google.com> From: Ashish Agarwal Date: Thu, 20 Dec 2012 10:24:08 -0500 Message-ID: To: Jeremy Yallop Cc: Caml List , Eric Jaeger , Philippe Wang Content-Type: multipart/alternative; boundary=f46d0434bdd2af2d2f04d14a53f4 Subject: Re: [Caml-list] Function returning recursive lists --f46d0434bdd2af2d2f04d14a53f4 Content-Type: text/plain; charset=ISO-8859-1 It would be nice to have metaocaml as one of the available compilers in opam. Anyone thinking of doing that? On Wed, Dec 19, 2012 at 6:50 PM, Jeremy Yallop wrote: > On 19 December 2012 22:23, Philippe Wang wrote: > > I have a (somehow silly) answer to your question: > > > > let gen_make_circ n = > > Printf.printf "let make_circ = function [] -> []\n"; > > That's an interesting idea, Philippe. Here's an approach along the > same lines using MetaOCaml. > > let rec docycle l = > .!(.< let rec s = > .~(let rec loop = function > | [] -> .< s >. > | x :: xs -> .< x :: .~(loop xs) >. > in loop l) > in s >.) > > The essential idea is the same as in your code: dynamically generating > a suitable 'let rec' expression. However, MetaOCaml also helpfully > guarantees that the generated code is well-formed and well-typed, and > makes it possible to compile and run the generated code without > leaving the language. > > Here's the code in action: > > # docycle;; > - : 'a list -> 'a list = > # docycle [1;2;3];; > - : int list = [1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; > 3; 1; ...] > # docycle [1;2;3;4;5];; > - : int list = [1; 2; 3; 4; 5; 1; 2; 3; 4; 5; 1; 2; 3; 4; 5; 1; 2; > 3; 4; ...] > > (For the sake of simplicity I haven't handled the case where the input > list is empty, but that's not difficult to do.) > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --f46d0434bdd2af2d2f04d14a53f4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable It would be nice to have metaocaml as one of the available compilers in opa= m. Anyone thinking of doing that?

On Wed,= Dec 19, 2012 at 6:50 PM, Jeremy Yallop <yallop@gmail.com> wr= ote:
On 19 December 2012 22:23,= Philippe Wang <mail@philippew= ang.info> wrote:
> I have a (somehow silly) answer to your question:
>
> let gen_make_circ n =3D
> =A0 Printf.printf "let make_circ =3D function [] -> []\n"= ;

That's an interesting idea, Philippe. =A0Here's an approach a= long the
same lines using MetaOCaml.

=A0 let rec docycle l =3D
=A0 =A0.!(.< let rec s =3D
=A0 =A0 =A0 =A0 =A0 .~(let rec loop =3D function
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| [] -> .< s >.
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| x :: xs -> .< x :: .~(loop xs) >.=
=A0 =A0 =A0 =A0 =A0 =A0 =A0in loop l)
=A0 =A0 =A0 =A0 =A0in s >.)

The essential idea is the same as in your code: dynamically generating
a suitable 'let rec' expression. =A0However, MetaOCaml also helpful= ly
guarantees that the generated code is well-formed and well-typed, and
makes it possible to compile and run the generated code without
leaving the language.

Here's the code in action:

=A0 =A0 # docycle;;
=A0 =A0 - : 'a list -> 'a list =3D <fun>
=A0 =A0 # docycle [1;2;3];;
=A0 =A0 - : int list =3D [1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2= ;
3; 1; ...]
=A0 =A0 # docycle [1;2;3;4;5];;
=A0 =A0 - : int list =3D [1; 2; 3; 4; 5; 1; 2; 3; 4; 5; 1; 2; 3; 4; 5; 1; 2= ;
3; 4; ...]

(For the sake of simplicity I haven't handled the case where the input<= br> list is empty, but that's not difficult to do.)

--
Caml-list mailing list. =A0Subscription management and archives:
ht= tps://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--f46d0434bdd2af2d2f04d14a53f4-- 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 11E5E7F2AA for ; Fri, 21 Dec 2012 20:55:31 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of pjfrey@sympatico.ca) identity=pra; client-ip=65.55.116.17; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="pjfrey@sympatico.ca"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of pjfrey@sympatico.ca designates 65.55.116.17 as permitted sender) identity=mailfrom; client-ip=65.55.116.17; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="pjfrey@sympatico.ca"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@blu0-omc1-s6.blu0.hotmail.com) identity=helo; client-ip=65.55.116.17; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="postmaster@blu0-omc1-s6.blu0.hotmail.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8AAKe91FBBN3QRk2dsb2JhbAA8CYY6tmtVFg4BAQEBCQkLCRQDJIIeAQEFIwRSEAsYAgImAgJXFAILiAujR5J4gSKLOg2BCIIWMmEDiGKHfoZHhDoVjW8 X-IronPort-AV: E=Sophos;i="4.84,331,1355094000"; d="scan'208";a="166577576" Received: from blu0-omc1-s6.blu0.hotmail.com ([65.55.116.17]) by mail4-smtp-sop.national.inria.fr with ESMTP; 21 Dec 2012 20:55:29 +0100 Received: from BLU0-SMTP100 ([65.55.116.7]) by blu0-omc1-s6.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 21 Dec 2012 11:55:28 -0800 X-EIP: [xHmP1Wq49/D+JNZKgudJOQcUBVQ0aV7X] X-Originating-Email: [pjfrey@sympatico.ca] Message-ID: Received: from [192.168.2.11] ([74.12.92.52]) by BLU0-SMTP100.blu0.hotmail.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Fri, 21 Dec 2012 11:55:27 -0800 From: Peter Frey To: caml-list@inria.fr CC: Eric Jaeger In-Reply-To: <003801cddcfa$f66325c0$e3297140$@jaeger@ssi.gouv.fr> References: <003801cddcfa$f66325c0$e3297140$@jaeger@ssi.gouv.fr> Content-Type: text/plain; charset="UTF-8" Date: Fri, 21 Dec 2012 14:55:26 -0500 MIME-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 21 Dec 2012 19:55:27.0771 (UTC) FILETIME=[1FB606B0:01CDDFB5] Subject: Re: [Caml-list] Function returning recursive lists On Tue, 2012-12-18 at 09:37 +0100, Eric Jaeger wrote: > Hi everyone, >=20 >=20=20 >=20 > There are various discussions on recursive lists in the archive, yet I > was wondering whether or not it was possible in pure OCaml to write a > function returning non-constant recursive lists. >=20 >=20=20 >=20 > For example, I would like to have a function =E2=80=9Cdocycle:=E2=80=99a = list->=E2=80=99a > list=E2=80=9D that takes a non recursive list and transforms it into a > recursive list containing the same elements. That is, =E2=80=9Cdocycle > [1;2;3]=E2=80=9D would return a list structurally equivalent to =E2=80=9C= let rec > c=3D1::2::3::c in c=E2=80=9D. So far, my various attempts (OCaml 3.12) ha= ve not > been successful. Another good example is to have a List.map compatible > with recursive lists. >=20 >=20=20 >=20 > Please note that it is, in a way, a theoretical (and possibly na=C3=AFve) > question : >=20 > - I do not consider recursive lists as the perfect > implementation for my problem >=20 > - I do not care about efficiency >=20 > - I do not want to use an ad hoc mutable/lazy list datatype > (unless I=E2=80=99ve also a conversion function toward standard lists) >=20 > - I do not want to use Obj or other similar tricks >=20 > It=E2=80=99s just that I=E2=80=99m curious whether or not what I=E2=80=99= m trying to achieve > is possible. >=20 >=20=20 >=20 > Regards, Eric >=20 It sometimes helps to read read the various libraries. For example, this thing is a variation of Batteries.BatList.Append: module Cycle =3D struct type 'a mut_list =3D { hd: 'a; mutable tl: 'a list } external inj : 'a mut_list -> 'a list =3D "%identity" external jni : 'a list -> 'a mut_list =3D "%identity" =20 let docycle =3D function (* copy and convert to circular *) | [] -> raise (Failure"Cannot make [] circular") | h0 :: t -> let r =3D { hd =3D h0; tl =3D [] } in let rec loop dst =3D function | [] -> dst.tl <- inj r; dst.tl | h :: t -> let cell =3D { hd =3D h; tl =3D [] } in dst.tl <- inj cell; loop cell t in loop r t let docycle =3D function (* convert to circular in place *) | [] -> raise (Failure"Cannot make [] circular") | ll -> let rec aux dst =3D=20 if dst.tl =3D [] then begin (* at end : *) dst.tl <- ll; (* replace last cell with ll *) List.tl (inj dst) (* and rotate to begin *) end else aux (jni (dst.tl)); (* advance *) in aux (jni ll) end let a =3D Cycle.docycle (ExtLib.String.explode "1234") let _ =3D let open Printf in List.iter print_char (ExtLib.List.take 50 a)= =20 $peter@ubuntu:~/ocaml/dink$ ./a.out=20 12341234123412341234123412341234123412341234123412peter@ubuntu:~/ocaml/dink= $=20 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 002B47F2B5 for ; Sat, 22 Dec 2012 19:10:14 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of philippe.wang.lists@gmail.com) identity=pra; client-ip=209.85.219.51; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of philippe.wang.lists@gmail.com designates 209.85.219.51 as permitted sender) identity=mailfrom; client-ip=209.85.219.51; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-oa0-f51.google.com) identity=helo; client-ip=209.85.219.51; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="postmaster@mail-oa0-f51.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhsJAG721VDRVdszm2dsb2JhbAA8CYVzAakOjwIIFg4BAQEBAQgJCwkUJ4IeAQEFJxkBOAEDDAEFBQsDCi4iEgEFARwGE4gBAw+XI48uhDcnDYlPAQUMjEsSCYQoA41UiDiOaBYpgVeCP4Fs X-IronPort-AV: E=Sophos;i="4.84,336,1355094000"; d="scan'208";a="187364975" Received: from mail-oa0-f51.google.com ([209.85.219.51]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 22 Dec 2012 19:10:14 +0100 Received: by mail-oa0-f51.google.com with SMTP id n12so5732820oag.38 for ; Sat, 22 Dec 2012 10:10:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=sxMeCrIodsvrumuhANRO+WiUlRtnwyOFCjqgXJxrSNU=; b=KSK64YKHNuyMm+Y+zXgOVktlCggQX4TWW1yekzN2CGbuZ8lprORncwajPIFXtACS4o 3Pqjv6Bz3aOdfBYbWvWydnf6kwcO5EFCD1v0NRp8ddaDQ8TmcLcD7k5oh8HwWx31qDZK raoG25AMDCSljMe+o9BjQF5Q0fnXbkIEstajmSWDKoXUIshgAZis+bswTkREts7Ip1Dg xovwOUvcqaSL47gY/clKQ+eCRcpSCsdhDXiftUcD5gIrLRYd91QRarO2oQOaOnOEBrxB CUseeUT3C+1JswCDfrAV0FHn3SiHnIQ05POQ0kX2J8vXvrBejaXf7obXcmarPv0JFihk 7UvA== MIME-Version: 1.0 Received: by 10.60.30.231 with SMTP id v7mr317052oeh.22.1356199812969; Sat, 22 Dec 2012 10:10:12 -0800 (PST) Sender: philippe.wang.lists@gmail.com Received: by 10.76.86.234 with HTTP; Sat, 22 Dec 2012 10:10:12 -0800 (PST) In-Reply-To: References: Date: Sat, 22 Dec 2012 19:10:12 +0100 X-Google-Sender-Auth: 5p8dJJRDPRXDokdyuK_5rb2K3Ps Message-ID: From: Philippe Wang To: Peter Frey Cc: OCaml Mailing List , Eric Jaeger Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] Function returning recursive lists On Fri, Dec 21, 2012 at 8:55 PM, Peter Frey wrote: > external inj : 'a mut_list -> 'a list = "%identity" > external jni : 'a list -> 'a mut_list = "%identity" This is exactly like using Obj.magic ! ;-) -- Philippe Wang mail@philippewang.info 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id EE3A57EE94 for ; Fri, 28 Dec 2012 02:41:32 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of pjfrey@sympatico.ca) identity=pra; client-ip=65.55.116.35; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="pjfrey@sympatico.ca"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of pjfrey@sympatico.ca designates 65.55.116.35 as permitted sender) identity=mailfrom; client-ip=65.55.116.35; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="pjfrey@sympatico.ca"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@blu0-omc1-s24.blu0.hotmail.com) identity=helo; client-ip=65.55.116.35; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="postmaster@blu0-omc1-s24.blu0.hotmail.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwBAEH43FBBN3QjlGdsb2JhbAA7CYY6s1mCeVgWDgEBAQEJCwkJFAMkgh4BAQUjBFIQCxgCAiYCAlcGDgIeh3ikSJF3gSKLNQUNgx4yYQOIYod/iwEVjW8 X-IronPort-AV: E=Sophos;i="4.84,366,1355094000"; d="scan'208";a="187761378" Received: from blu0-omc1-s24.blu0.hotmail.com ([65.55.116.35]) by mail1-smtp-roc.national.inria.fr with ESMTP; 28 Dec 2012 02:41:32 +0100 Received: from BLU0-SMTP86 ([65.55.116.9]) by blu0-omc1-s24.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 27 Dec 2012 17:41:31 -0800 X-EIP: [4/DG88+/etQwtCXXGDO5vYwq4FBSdv1G] X-Originating-Email: [pjfrey@sympatico.ca] Message-ID: Received: from [192.168.2.11] ([70.27.1.137]) by BLU0-SMTP86.blu0.hotmail.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Thu, 27 Dec 2012 17:41:30 -0800 From: Peter Frey To: "Eric Jaeger (ANSSI)" CC: caml-list@inria.fr In-Reply-To: <50D59147.3000201@ssi.gouv.fr> References: <003801cddcfa$f66325c0$e3297140$@jaeger@ssi.gouv.fr> <50D59147.3000201@ssi.gouv.fr> Content-Type: text/plain; charset="UTF-8" Date: Thu, 27 Dec 2012 20:41:28 -0500 MIME-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 28 Dec 2012 01:41:30.0195 (UTC) FILETIME=[758F0230:01CDE49C] Subject: Re: [Caml-list] Function returning recursive lists On Sat, 2012-12-22 at 11:53 +0100, Eric Jaeger (ANSSI) wrote: > On 21/12/2012 20:55, Peter Frey wrote: > > It sometimes helps to read read the various libraries. > > For example, this thing is a variation of Batteries.BatList.Append: > > > > module Cycle = struct > > type 'a mut_list = { hd: 'a; mutable tl: 'a list } > > external inj : 'a mut_list -> 'a list = "%identity" > > external jni : 'a list -> 'a mut_list = "%identity" > As far as I know, the use of "%identity" is a trick which is similar to > Obj, telling the compiler to do nothing. You would not be allowed to do > that with standard, typed OCaml identity. In this sense, it is not the > sort of solution I'm looking for. > > Regards, Eric For what it's worth: Obj.ml, contains the line: ... external magic : 'a -> 'b = "%identity" ... That type allows anything, including 'unifying' any two types. (The compiler does not do nothing: it assigns the argument of type 'a to be the result which is of type 'b and is perfectly willing to produce code that instantly causes a segmentation fault) inj and its inverse jni seem to have a type at least a bit more friendly since they control the usage of the individual fields. As long as you trust Ocaml lists to always have the layout above, this seems a lot saver to me than type 'a -> 'b. You wanted, in effect, something like: # let rec l = [1;2;3;l];; Error: This expression has type int list but an expression was expected of type int The type 'a list is built into the system; it is not recursive and if there was a way to force it to be so (without hacks), the type system would not be sound. You know the following, of course: # type 'a aRec = {mutable hd: 'a; mutable tl:'a aRec};; type 'a aRec = { mutable hd : 'a; mutable tl : 'a aRec; } # let rec a = {hd=1; tl=a};; val a : int aRec = {hd = 1; tl = {hd = 1; tl = {hd = 1; tl = {hd = 1; tl = The problem with docycle is not its coding style but that it produces in fact a cyclic list, which is not very useful: Almost all functions, such as List.rev are undefined. Peter 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 9FB417EE94 for ; Fri, 28 Dec 2012 10:37:36 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of grazingcows@yahoo.com) identity=pra; client-ip=98.136.217.18; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="grazingcows@yahoo.com"; x-sender="grazingcows@yahoo.com"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of grazingcows@yahoo.com) identity=mailfrom; client-ip=98.136.217.18; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="grazingcows@yahoo.com"; x-sender="grazingcows@yahoo.com"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@nm35.bullet.mail.gq1.yahoo.com) identity=helo; client-ip=98.136.217.18; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="grazingcows@yahoo.com"; x-sender="postmaster@nm35.bullet.mail.gq1.yahoo.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AugNAERn3VBiiNkSamdsb2JhbAA3BAmCSY0Kmz+SVBYODQkMBhQpghkFAQEFCxwEFQECFRYMAQ4GBREEAQEBDSEvAQ4BBgoIBhMSCYdlAQECDwQIpS8JgnKED0gBIwMBIwOIdAEGCgEBjEsFDYQxA4hijTGBFYRPLlCIFWuDdA X-IronPort-AV: E=Sophos;i="4.84,368,1355094000"; d="scan'208,217";a="166943654" Received: from nm35.bullet.mail.gq1.yahoo.com ([98.136.217.18]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Dec 2012 10:37:34 +0100 Received: from [98.137.12.191] by nm35.bullet.mail.gq1.yahoo.com with NNFMP; 28 Dec 2012 09:37:31 -0000 Received: from [98.137.12.247] by tm12.bullet.mail.gq1.yahoo.com with NNFMP; 28 Dec 2012 09:37:31 -0000 Received: from [127.0.0.1] by omp1055.mail.gq1.yahoo.com with NNFMP; 28 Dec 2012 09:37:31 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 548392.17401.bm@omp1055.mail.gq1.yahoo.com Received: (qmail 86193 invoked by uid 60001); 28 Dec 2012 09:37:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1356687451; bh=X9305ekopiTiRJ9ttN3vgJOEOeV/G3pVeEdaUQqdW8g=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=j0OI2UHM97ZkOeS1ws+nKpx7gS+3bYqSRqG51Uadx4niZAG35sNtAEdcFo6/7+m6KVYr57gyDt6GGe8ERpuAIU9pFD3C1OfOiBuaN6Kdn7VcJxJGpjH7SC9Oml/Kz4262CjV1Z6jfr3OwLPMfc+LA3PwQF30eSXUPPqa7KUEpe4= DomainKey-Signature:a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=pFWXwj/6Fx03+RQx/WGfDpa6ATIJJwNfcQrWyunU+WbDhR8dINKUTHZx7LfamIklEf4+g+o2fjEX6qQSb+MNrL7arkqyiZZ4GWnUb5nnM1ZyUelXGlitqrHQFzSmx/LIMHS1Cw2odoGFUu2odfrljH9suOfFRokZpdFtkcpkris=; X-YMail-OSG: QCtC68MVM1nzCXvuAziWjih4RHmsOlvwnsXT4HhlYZEEVV6 wz4NoJX.dD14Ni4G5Ui3H65eBjXbeWl9FZUCJbdbg9Vs5VML3eyFcv5P7MPR d51w8GaOF.gz8LpAFrJab1nn7zx6jWHtRzCcPe5IOjhoS8dwileyJsjN1TVF By1B0F8ayQ3iQxr5YdpvsRqOX.ymShqdRodYqkTonmX4hG6hZWyVcVOAMoG_ bmuXq.yyKNqEUDmUWJDGBYdVxT7tkrZWWV2EqqMsSbDqzBByv71XIfvVbhUp VqzorX1ibp.f0pN.OsIjQsRSliEBAEcUBLhuW8zSRLdEErZ6RwkFlUh9nrF_ BI5szd.njgDp3pU9t_kbxFz.PxVjylw4D9ku.HasJ3F6MDxRyY1H5JfQVLes NUE2.tpSQcBkqjp7XMeaGZ0rMeXobuiGPPFl5LaOs8EOaclm3mK3qZYWjONw NOxT3L4BkrWHHhZUO4ZKN4H_AFIGTig9IJAbD0eHahp4vABlc9bvECvVH4xB YbVBV2QqcNEmmi1ZUm_BfwlzK6aWtHpngnRbRevo4818q78jkLgnTEJ36I4V Gh6eM5wK9WfzSwDMYJfWTVGhKFxsAkBpTprIqUg7e4sBuFqxovPY4pOzikBb RpUAkl8MZ5K5Wb5pJNVdlfuOMuOQWcLsJIljZ5D659Hu3X.CRukDR Received: from [141.0.8.139] by web163402.mail.gq1.yahoo.com via HTTP; Fri, 28 Dec 2012 01:37:31 PST X-Rocket-MIMEInfo: 001.001,SGkswqAKCgpZb3UgY2Fubm90IGhhdmUgYSBjaXJjdWxhciByZWN1cnNpdmUgZGVmaW5pdGlvbgoKbGV0IHJlYyBscyA9IFsxOyAyOyAzOyBsczsgXSA7OwoKYnV0IHlvdSBjYW4gaGF2ZSBhICJjaXJjdWxhciIgbGlzdDoKCmxldCByZWMgbHMgPSBbMTsgMjsgMztdIDo6IGxzIDs7CgppdCBjcmVhdGVzIDQwIGl0ZW1zLAp0aGUgZmlyc3QgMzggYXJlIFsxOyAyOyAzO10gYW5kIHRoZSAzOSBpc8KgClsxOyAyOyAuLi5dOyBhbmQgdGhlIGxhc3QgWy4uLl0uwqAKV2UgY2Fubm90IHNheSBpdCBpcyBhIHRydWUgJ2MBMAEBAQE- X-Mailer: YahooMailWebService/0.8.129.483 References: <003801cddcfa$f66325c0$e3297140$@jaeger@ssi.gouv.fr> <50D59147.3000201@ssi.gouv.fr> Message-ID: <1356687451.79354.YahooMailNeo@web163402.mail.gq1.yahoo.com> Date: Fri, 28 Dec 2012 01:37:31 -0800 (PST) From: Arkady Andrukonis Reply-To: Arkady Andrukonis To: "caml-list@inria.fr" In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="303371348-562022172-1356687451=:79354" Subject: Re: [Caml-list] Function returning recursive lists --303371348-562022172-1356687451=:79354 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi,=A0 You cannot have a circular recursive definition let rec ls =3D [1; 2; 3; ls; ] ;; but you can have a "circular" list: let rec ls =3D [1; 2; 3;] :: ls ;; it creates 40 items, the first 38 are [1; 2; 3;] and the 39 is=A0 [1; 2; ...]; and the last [...].=A0 We cannot say it is a true 'circular' list, because we don't return from the last element to the=A0 first element. At any rate this will result=20 in an expression that is nested too deep and=20 we won't be able to use it. The ellipsis [...] has the force of 'any' but it returns the same element as before, a list of lists. An example of a not very useful circular list in the literature=20 shows a continuous loop let rec process =3D 1 :: 2 :: 3 :: 4 :: 5 :: process;; while true do =A0 let process :: process =3D process in =A0 printf "Handling =A0process %d\n" process; =A0 Unix.sleep 2; done ;; ________________________________ From: Peter Frey To: Eric Jaeger (ANSSI) =20 Cc: caml-list@inria.fr=20 Sent: Thursday, December 27, 2012 8:41 PM Subject: Re: [Caml-list] Function returning recursive lists =20 On Sat, 2012-12-22 at 11:53 +0100, Eric Jaeger (ANSSI) wrote:=20 > On 21/12/2012 20:55, Peter Frey wrote: > > It sometimes helps to read read the various libraries. > > For example, this thing is a variation of Batteries.BatList.Append: > > > > module Cycle =3D struct > >=A0 =A0 type 'a mut_list =3D { hd: 'a; mutable tl: 'a list } > >=A0 =A0 external inj : 'a mut_list -> 'a list =3D "%identity" > >=A0 =A0 external jni : 'a list -> 'a mut_list =3D "%identity" > As far as I know, the use of "%identity" is a trick which is similar to= =20 > Obj, telling the compiler to do nothing. You would not be allowed to do= =20 > that with standard, typed OCaml identity. In this sense, it is not the=20 > sort of solution I'm looking for. >=20 >=A0 =A0 Regards, Eric For what it's=A0 worth: Obj.ml, contains the line: ... external magic : 'a -> 'b =3D "%identity" ... That type allows anything, including 'unifying' any two types. (The compiler does not do nothing: it assigns the argument of type 'a to be the result which is of type 'b and is perfectly willing to produce code that instantly causes a segmentation fault) inj and its inverse jni seem to have a type at least a bit more friendly since they control the usage of the individual fields. As long as you trust Ocaml lists to always have the layout above, this seems a lot saver to me than type 'a -> 'b. You wanted, in effect, something like: # let rec l =3D [1;2;3;l];; Error: This expression has type int list =A0 =A0 =A0 but an expression was expected of type int The type 'a list is built into the system; it is not recursive and if there was a way to force it to be so (without hacks), the type system would not be sound. You know the following, of course: # type 'a aRec =3D {mutable hd: 'a; mutable tl:'a aRec};; type 'a aRec =3D { mutable hd : 'a; mutable tl : 'a aRec; } # let rec a =3D {hd=3D1; tl=3Da};;=A0 =A0 =A0 =A0 =A0=20 val a : int aRec =3D =A0 {hd =3D 1; =A0 tl =3D =A0 =A0 {hd =3D 1; =A0 =A0 tl =3D =A0 =A0 =A0 {hd =3D 1; =A0 =A0 =A0 tl =3D =A0 =A0 =A0 =A0 {hd =3D 1; =A0 =A0 =A0 =A0 tl =3D The problem with docycle is not its coding style but that it produces in fact a cyclic list, which is not very useful: Almost all functions, such as List.rev are undefined.=20 Peter --=20 Caml-list mailing list.=A0 Subscription management and archives: https://sympa.inria.fr/sympa/arc/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs= --303371348-562022172-1356687451=:79354 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Hi, 

You cannot have a circular recursi= ve definition
let rec ls =3D [1; 2; 3; ls; ] ;;
but you can have a "circular" list:
let rec ls =3D [1; 2; 3;] :: = ls ;;
it creates 40 items,
the first 38 are = [1; 2; 3;] and the 39 is 
[1; 2; ...]; and the last [...].&n= bsp;
We cannot say it is a true 'circular' list, because
we don't return from the last element to the 
first elemen= t. At any rate this will result
in an expression that is nested = too deep and
we won't be able to use it. The ellipsis [...] has<= /div>
the force of 'any' but it returns the same element
as b= efore, a list of lists. An example of a not
very useful circular = list in the literature
shows a continuous loop
let rec= process =3D 1 :: 2 :: 3 :: 4 :: 5 :: process;;
while true do
  let process :: process =3D process in
  printf "Handling  process %d\n" process;
  Unix.sleep = 2;
done ;;

From: Peter Frey <pjfrey@sympatico.ca>
= To: Eric Jaeger (ANSSI) &= lt;eric.jaeger@ssi.gouv.fr>
Cc= : caml-list@inria.fr
= Sent: Thursday, December 27, 2012 8:41 PM
Subject: Re: [Caml-list] Function returning = recursive lists

On Sat, 2012-12-22 at 11:53 +0100, Eric Jaeger (ANSSI) wrote:
> On 2= 1/12/2012 20:55, Peter Frey wrote:
> > It sometimes helps to read = read the various libraries.
> > For example, this thing is a varia= tion of Batteries.BatList.Append:
> >
> > module Cycle = =3D struct
> >    type 'a mut_list =3D { hd: 'a; mutable= tl: 'a list }
> >    external inj : 'a mut_list -> '= a list =3D "%identity"
> >    external jni : 'a list -&g= t; 'a mut_list =3D "%identity"
> As far as I know, the use of "%ident= ity" is a trick which is similar to
> Obj, telling the compiler to d= o nothing. You would not be allowed to do
> that with standard, type= d OCaml identity. In this sense, it is not the
> sort of solution I'= m looking for.
>
>    Regards, Eric

For what = it's  worth: Obj.ml, contains the line:
...
external magic : 'a -> 'b =3D "%identity"<= br>...
That type allows anything, including 'unifying' any two types.(The compiler does not do nothing: it assigns the argument of type 'a tobe the result which is of type 'b and is perfectly willing to produce
= code that instantly causes a segmentation fault)

inj and its inverse= jni seem to have a type at least a bit more friendly
since they control= the usage of the individual fields.
As long as you trust Ocaml lists to= always have the layout above, this
seems a lot saver to me than type 'a= -> 'b.

You wanted, in effect, something like:
# let rec l =3D= [1;2;3;l];;
Error: This expression has type int list
    &= nbsp; but an expression was expected of type int

The type 'a list i= s built into the system; it is not recursive and if
there was a way to f= orce it to be so (without hacks), the type system
would not be sound.

You know the following, of course:

# type 'a aRec =3D= {mutable hd: 'a; mutable tl:'a aRec};;
type 'a aRec =3D { mutable hd : = 'a; mutable tl : 'a aRec; }

# let rec a =3D {hd=3D1; tl=3Da};; =        
val a : int aRec =3D
  {hd =3D 1;=
  tl =3D
    {hd =3D 1;
    tl =3D
=       {hd =3D 1;
      tl =3D
  &= nbsp;     {hd =3D 1;
        tl =3D
The problem with docycle is not its coding style but that it produces in<= br>fact a cyclic list, which is not very useful: Almost all functions, such=
as List.rev are undefined.


Peter





-- =
Caml-list mailing list.  Subscription management and archives:
= ht= tps://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.= inria.fr/bin/caml-bugs


= --303371348-562022172-1356687451=:79354-- 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id CE95B7EE94 for ; Fri, 28 Dec 2012 13:21:37 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of philippe.wang.lists@gmail.com) identity=pra; client-ip=209.85.212.176; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of philippe.wang.lists@gmail.com designates 209.85.212.176 as permitted sender) identity=mailfrom; client-ip=209.85.212.176; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f176.google.com) identity=helo; client-ip=209.85.212.176; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="postmaster@mail-wi0-f176.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmcKAH+N3VDRVdSwk2dsb2JhbAA8CasTg0yPAAgWDgEBAQEJCQsJFAQjgh4BAQQBJxkBLQsBAwELAQUFCwMDBAEBAQ0hIhIBBQEKCggGExIJh2YDCQYMmRGPLoR4JwMKiGsBBQyLYWoFDQQFhCgDjVSGZoFSgRyKG4MxFimBV4I/gWQIFw X-IronPort-AV: E=Sophos;i="4.84,369,1355094000"; d="scan'208";a="187802365" Received: from mail-wi0-f176.google.com ([209.85.212.176]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Dec 2012 13:21:37 +0100 Received: by mail-wi0-f176.google.com with SMTP id hm6so8209805wib.3 for ; Fri, 28 Dec 2012 04:21:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=BS4wVrPJ2EBONxJc8g0L+v0HxlIrMQzI3vH9VB8hIsI=; b=GDeTh9nTOAMjIX7HWYZ0R8hmxKDH8ejtNaC74jo0iGCExmiZ0TuWacMAYXqqqTOfMy mE3mkVPjEVXGQa9ebTtnqjMP8vULLi2ZsJXgX40wpzDlRPzVYP0mOzFIHN9m5SnQ2kIN qpye2D0HsqIvSnI8fYpwYke25nM2tb46szKHTyhULr/lVDcpDPKLlUqM90W5kEYZMvgl HVzmr0yw9N80j6PjGnLbDN17l/oVChE5bWVIIG8kypMvw5h+8GeV10xH6zYQF/sOrFY1 jKg5eu5kyVFYyVbZW1q/vLe77aD5KsRs5L5+M9Ts4wF5aVOoVcF9eVkzp6ydKDteWv3k 3jxQ== MIME-Version: 1.0 Received: by 10.180.99.72 with SMTP id eo8mr45148431wib.34.1356697296878; Fri, 28 Dec 2012 04:21:36 -0800 (PST) Sender: philippe.wang.lists@gmail.com Received: by 10.216.16.82 with HTTP; Fri, 28 Dec 2012 04:21:36 -0800 (PST) In-Reply-To: <1356687451.79354.YahooMailNeo@web163402.mail.gq1.yahoo.com> References: <50D59147.3000201@ssi.gouv.fr> <1356687451.79354.YahooMailNeo@web163402.mail.gq1.yahoo.com> Date: Fri, 28 Dec 2012 13:21:36 +0100 X-Google-Sender-Auth: QMIzWAEV3B7WBB9xsMtUQNeUtqE Message-ID: From: Philippe Wang To: Arkady Andrukonis Cc: "caml-list@inria.fr" Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] Function returning recursive lists > let rec ls = [1; 2; 3;] :: ls ;; > it creates 40 items, > the first 38 are [1; 2; 3;] and the 39 is > [1; 2; ...]; and the last [...]. Actually, no, it does *not* create 40 items at all: the printer make no difference between circular data and big data. If one creates a list with 1000 elements, only the first X elements are displayed by "ocaml top-level interactive loop". (X depends on the size of the printed data) If the 39th is "[1; 2; ...]", it's only because the printer has reached the limit at "2" and won't go further to "see" that there's only a "3" remaining in that list. (Reminder: computers are particularly dumb, they only do (exactly) what we tell them to do.) let rec ls = [1; 2; 3;] :: ls ;; allocates [1; 2; 3;] and then a circular block (b) containing two elements: 1. a pointer to that list ([1; 2; 3;]) and 2. a pointer to itself (b). Try this: Array.to_list (Array.make 1000 42);; And maybe try this: List.length (Array.to_list (Array.make 1000 42));; Cheers, Philippe Wang On Fri, Dec 28, 2012 at 10:37 AM, Arkady Andrukonis wrote: > Hi, > > You cannot have a circular recursive definition > let rec ls = [1; 2; 3; ls; ] ;; > but you can have a "circular" list: > let rec ls = [1; 2; 3;] :: ls ;; > it creates 40 items, > the first 38 are [1; 2; 3;] and the 39 is > [1; 2; ...]; and the last [...]. > We cannot say it is a true 'circular' list, because > we don't return from the last element to the > first element. At any rate this will result > in an expression that is nested too deep and > we won't be able to use it. The ellipsis [...] has > the force of 'any' but it returns the same element > as before, a list of lists. An example of a not > very useful circular list in the literature > shows a continuous loop > let rec process = 1 :: 2 :: 3 :: 4 :: 5 :: process;; > while true do > let process :: process = process in > printf "Handling process %d\n" process; > Unix.sleep 2; > done ;; > ________________________________ > From: Peter Frey > To: Eric Jaeger (ANSSI) > Cc: caml-list@inria.fr > Sent: Thursday, December 27, 2012 8:41 PM > Subject: Re: [Caml-list] Function returning recursive lists > > On Sat, 2012-12-22 at 11:53 +0100, Eric Jaeger (ANSSI) wrote: >> On 21/12/2012 20:55, Peter Frey wrote: >> > It sometimes helps to read read the various libraries. >> > For example, this thing is a variation of Batteries.BatList.Append: >> > >> > module Cycle = struct >> > type 'a mut_list = { hd: 'a; mutable tl: 'a list } >> > external inj : 'a mut_list -> 'a list = "%identity" >> > external jni : 'a list -> 'a mut_list = "%identity" >> As far as I know, the use of "%identity" is a trick which is similar to >> Obj, telling the compiler to do nothing. You would not be allowed to do >> that with standard, typed OCaml identity. In this sense, it is not the >> sort of solution I'm looking for. >> >> Regards, Eric > > For what it's worth: Obj.ml, contains the line: > ... > external magic : 'a -> 'b = "%identity" > ... > That type allows anything, including 'unifying' any two types. > (The compiler does not do nothing: it assigns the argument of type 'a to > be the result which is of type 'b and is perfectly willing to produce > code that instantly causes a segmentation fault) > > inj and its inverse jni seem to have a type at least a bit more friendly > since they control the usage of the individual fields. > As long as you trust Ocaml lists to always have the layout above, this > seems a lot saver to me than type 'a -> 'b. > > You wanted, in effect, something like: > # let rec l = [1;2;3;l];; > Error: This expression has type int list > but an expression was expected of type int > > The type 'a list is built into the system; it is not recursive and if > there was a way to force it to be so (without hacks), the type system > would not be sound. > > You know the following, of course: > > # type 'a aRec = {mutable hd: 'a; mutable tl:'a aRec};; > type 'a aRec = { mutable hd : 'a; mutable tl : 'a aRec; } > > # let rec a = {hd=1; tl=a};; > val a : int aRec = > {hd = 1; > tl = > {hd = 1; > tl = > {hd = 1; > tl = > {hd = 1; > tl = > > The problem with docycle is not its coding style but that it produces in > fact a cyclic list, which is not very useful: Almost all functions, such > as List.rev are undefined. > > > Peter > > > > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > -- Philippe Wang mail@philippewang.info 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 2009A7EE94 for ; Fri, 28 Dec 2012 13:30:34 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of philippe.wang.lists@gmail.com) identity=pra; client-ip=209.85.212.170; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of philippe.wang.lists@gmail.com designates 209.85.212.170 as permitted sender) identity=mailfrom; client-ip=209.85.212.170; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f170.google.com) identity=helo; client-ip=209.85.212.170; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="postmaster@mail-wi0-f170.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmIKAKaQ3VDRVdSqk2dsb2JhbABFrl+PAAgWDgEBAQEJCQsJFAQjgh4BAQQBQAE4AQMBCwEFBQsDOCISAQUBHAYTiAEDCQaZIY8uhHgnDYhrAQUMjEsbhCgDjVSIOI5oFimBV4I/gWw X-IronPort-AV: E=Sophos;i="4.84,369,1355094000"; d="scan'208";a="166954013" Received: from mail-wi0-f170.google.com ([209.85.212.170]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Dec 2012 13:30:04 +0100 Received: by mail-wi0-f170.google.com with SMTP id hq7so5086405wib.5 for ; Fri, 28 Dec 2012 04:30:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=I3NOxJT9i2aphb+bBGqAW1L1yJgeagpEhp9TpRpjvkk=; b=BEO7hwvBFikmlTTKadwiyccp6g6JZ/xadXHdeiyLncG/4SGY+J7wydw5uCx666y+Sp opI1r8tErYlHvak7875jSNo5fa4IJyfc2AqPJDMhmp4MV2ojdWrjlCLWx1XzHYOmpzqH IljwWP3HM/NQ5A0z6bHOjCdAZsLe/2rQYfZPgBR4ukO3YUsQ5yP0CYy5EYGza+DVAXZz iFtdsYutUPaTa95P0hVYLX2udXBKvPF8R6MlapSr23aYNavlSczJsdJaMPj3JF+g51ED k0Bjv3NqyXoBtg+xrsn3RqRkSiv64E+gMndO8h7zTCa7WNOnkYjShczy1snxKIsqSf4r gd8A== MIME-Version: 1.0 Received: by 10.180.75.208 with SMTP id e16mr52630594wiw.3.1356697803563; Fri, 28 Dec 2012 04:30:03 -0800 (PST) Sender: philippe.wang.lists@gmail.com Received: by 10.216.16.82 with HTTP; Fri, 28 Dec 2012 04:30:03 -0800 (PST) In-Reply-To: References: <50D59147.3000201@ssi.gouv.fr> Date: Fri, 28 Dec 2012 13:30:03 +0100 X-Google-Sender-Auth: p93B1IRhuip12yIbgxmzNhvTFNY Message-ID: From: Philippe Wang To: Peter Frey Cc: "Eric Jaeger (ANSSI)" , OCaml Mailing List Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] Function returning recursive lists On Fri, Dec 28, 2012 at 2:41 AM, Peter Frey wrote: > The problem with docycle is not its coding style but that it produces in > fact a cyclic list, which is not very useful: Almost all functions, such > as List.rev are undefined. >From my point of view, this coding style is fundamentally *wrong*: - it makes assumptions on the internal data representation, - and it prevents the compiler from making any optimisation from the fact that elements of built-in lists are immutable (and if the compilers makes some optimisations from that fact, then it's not only the style but the program that is wrong). Cheers, -- Philippe Wang mail@philippewang.info 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 D69277EE94 for ; Fri, 28 Dec 2012 16:22:25 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of didier.cassirame@gmail.com) identity=pra; client-ip=209.85.214.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="didier.cassirame@gmail.com"; x-sender="didier.cassirame@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of didier.cassirame@gmail.com designates 209.85.214.182 as permitted sender) identity=mailfrom; client-ip=209.85.214.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="didier.cassirame@gmail.com"; x-sender="didier.cassirame@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ob0-f182.google.com) identity=helo; client-ip=209.85.214.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="didier.cassirame@gmail.com"; x-sender="postmaster@mail-ob0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnABAK643VDRVda2jWdsb2JhbABFhjqkWJJLCBYOAQEBAQkJCwkSBiOCHgEBBSMdARsSCwEDDAYFCwMKAgIJHQICIgERAQUBChIGExKHbgEDDwyZLItkT4J7hE4KGScDClmIEgEFDIEWizUbgxWBEwOWDIEcjUwWKYQWgWw X-IronPort-AV: E=Sophos;i="4.84,370,1355094000"; d="scan'208";a="166963228" Received: from mail-ob0-f182.google.com ([209.85.214.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Dec 2012 16:22:24 +0100 Received: by mail-ob0-f182.google.com with SMTP id 16so9720483obc.27 for ; Fri, 28 Dec 2012 07:22:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=DMsubi7Ml/M8pGLsHFtcT9NUcSWL5Nhu6ZEv9KllcLQ=; b=xzq644ZH3Onh57tvFHmIrGWZNYRguKe8nrI1rltt+nGauCl6hmvfB+X2WFQJFBnDvR Awjb7xpybNsobAUmiVsj898FNxpRWWYczb4Jm62+PdP/DgZwOVt8wL4C9ySERiwm1/aP Qu1Y3LMtj7uycZW9Wo+w6bFD72TZhJjRtxDMtnutLDPHaEZyz6fjhwNqtsqtrrMlOKOD Q8jw8DgSsqVpAnefK3cljV3Q2562ddN0IbJL15SUuR/1fzmXZRw75C3w67g1Lc4F6nOG IflS1hHZXZ9wzIoYz4O0LaMQecL1nnYyJ5teZeu4hdEOiEbCw1fPEBFVzEMXeMjgqrDp kRaQ== MIME-Version: 1.0 Received: by 10.60.32.33 with SMTP id f1mr16208793oei.122.1356708143657; Fri, 28 Dec 2012 07:22:23 -0800 (PST) Received: by 10.60.165.8 with HTTP; Fri, 28 Dec 2012 07:22:23 -0800 (PST) In-Reply-To: References: <50D59147.3000201@ssi.gouv.fr> Date: Fri, 28 Dec 2012 16:22:23 +0100 Message-ID: From: Didier Cassirame To: Philippe Wang Cc: Peter Frey , "Eric Jaeger (ANSSI)" , OCaml Mailing List Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Function returning recursive lists Hi all, Regarding the original question, wouldn't it be easier to implement it as a stream? didier 2012/12/28, Philippe Wang : > On Fri, Dec 28, 2012 at 2:41 AM, Peter Frey wrote: > >> The problem with docycle is not its coding style but that it produces in >> fact a cyclic list, which is not very useful: Almost all functions, such >> as List.rev are undefined. > > From my point of view, this coding style is fundamentally *wrong*: > - it makes assumptions on the internal data representation, > - and it prevents the compiler from making any optimisation from the > fact that elements of built-in lists are immutable (and if the > compilers makes some optimisations from that fact, then it's not only > the style but the program that is wrong). > > Cheers, > > -- > Philippe Wang > mail@philippewang.info > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 721F07EE94 for ; Fri, 4 Jan 2013 01:45:44 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of berenger@riken.jp) identity=pra; client-ip=134.160.33.161; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="berenger@riken.jp"; x-sender="berenger@riken.jp"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of berenger@riken.jp designates 134.160.33.161 as permitted sender) identity=mailfrom; client-ip=134.160.33.161; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="berenger@riken.jp"; x-sender="berenger@riken.jp"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of postmaster@postman.riken.jp designates 134.160.33.161 as permitted sender) identity=helo; client-ip=134.160.33.161; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="berenger@riken.jp"; x-sender="postmaster@postman.riken.jp"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ak8CAAsl5lCGoCGhkWdsb2JhbABFhjqkSJJkDgEBAQEUEhQngh4BAQQBIxU2CgYLCxgCAgUEEgsCAgkDAgECATMSEwYCAQEOh28DCQYMpxeIVwOGbYEiizUbf4IWgRMDiGCNLIEchE+NYIFi X-IronPort-AV: E=Sophos;i="4.84,406,1355094000"; d="scan'208";a="188399997" Received: from postman1.riken.jp (HELO postman.riken.jp) ([134.160.33.161]) by mail1-smtp-roc.national.inria.fr with ESMTP; 04 Jan 2013 01:45:42 +0100 Received: from postman.riken.jp (postman1.riken.jp [127.0.0.1]) by postman.riken.jp (Postfix) with SMTP id 3599032C01E4 for ; Fri, 4 Jan 2013 09:45:39 +0900 (JST) Received: from [172.27.98.103] (rikad98.riken.jp [134.160.214.98]) by postman.riken.jp (Postfix) with ESMTPA id 65B4632A0047 for ; Fri, 4 Jan 2013 09:45:38 +0900 (JST) Message-ID: <50E62632.4060208@riken.jp> Date: Fri, 04 Jan 2013 09:45:38 +0900 From: Francois Berenger User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: caml-list@inria.fr References: <50D59147.3000201@ssi.gouv.fr> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 5.6.0.2009776, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2013.1.4.3325 Subject: Re: [Caml-list] Function returning recursive lists On 12/29/2012 12:22 AM, Didier Cassirame wrote: > Hi all, > > Regarding the original question, wouldn't it be easier to implement it > as a stream? It smells as someone needs a stream or a lazy list indeed. Happy new year! ;) > didier > > 2012/12/28, Philippe Wang : >> On Fri, Dec 28, 2012 at 2:41 AM, Peter Frey wrote: >> >>> The problem with docycle is not its coding style but that it produces in >>> fact a cyclic list, which is not very useful: Almost all functions, such >>> as List.rev are undefined. >> >> From my point of view, this coding style is fundamentally *wrong*: >> - it makes assumptions on the internal data representation, >> - and it prevents the compiler from making any optimisation from the >> fact that elements of built-in lists are immutable (and if the >> compilers makes some optimisations from that fact, then it's not only >> the style but the program that is wrong). >> >> Cheers, >> >> -- >> Philippe Wang >> mail@philippewang.info >> >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa.inria.fr/sympa/arc/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs >> >