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