From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 18660BB84 for ; Mon, 17 Apr 2006 13:24:43 +0200 (CEST) Received: from swip.net (mailfe10.tele2.fr [212.247.155.44]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k3HBOgV7028998 for ; Mon, 17 Apr 2006 13:24:42 +0200 X-T2-Posting-ID: VOFteLZ+LTHhOWGZw3zDiXYGNWCfSPl1g+TbJcmKNB0= X-Cloudmark-Score: 0.000000 [] Received: from [213.103.202.93] (HELO lycoperdon.mycelium) by mailfe10.swip.net (CommuniGate Pro SMTP 5.0.8) with SMTP id 10967308 for caml-list@yquem.inria.fr; Mon, 17 Apr 2006 13:24:40 +0200 Date: Mon, 17 Apr 2006 13:26:07 +0200 From: Nils Gesbert To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] recursion/iterator question Message-Id: <20060417132607.e9dc2ad7.nils.gesbert@ens.fr> In-Reply-To: <44433AA3.9080908@crans.org> References: <1145221898.16349.259200911@webmail.messagingengine.com> <44433AA3.9080908@crans.org> X-Mailer: Sylpheed version 2.2.3 (GTK+ 2.4.1; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 44437AFA.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; nils:01 nils:01 recursion:01 iterator:01 iter:01 rec:01 iter:01 suffices:01 caml-list:01 behaviour:01 mistaken:01 functional:02 ens:02 let:03 let:03 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 Li-Thiao-Té Sébastien a écrit : » let iterate f l = » let t = Array.of_list l in » let n = Array.length t in » let results = ref [] in » for i = 0 to n-1 do » for j = 0 to n-1 do » for k = 0 to n-1 do » results := f (t.(i),t.(j),t.(k)) :: results » done done done » ;; Hi, A functional version of this could be (assuming f is curryed, and without keeping results) : let iter3 f l = let rec it2 iter g = function h::t -> iter (g h) l; it2 iter g t | _ -> () in it2 (it2 List.iter) f l But I think the goal was to iterate over triplets (a,b,c) with a < b < c, not over all triplets. If I am not mistaken, it suffices to replace the l on line 3 by t to get this behaviour. -- Nils Gesbert