caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nils Gesbert <nils.gesbert@ens.fr>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] recursion/iterator question
Date: Mon, 17 Apr 2006 13:26:07 +0200	[thread overview]
Message-ID: <20060417132607.e9dc2ad7.nils.gesbert@ens.fr> (raw)
In-Reply-To: <44433AA3.9080908@crans.org>

Li-Thiao-Té Sébastien <sayan@crans.org> 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


  reply	other threads:[~2006-04-17 11:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-16 21:11 Tato Thetza
2006-04-16 22:00 ` [Caml-list] " David Powers
2006-04-16 22:27 ` Martin Jambon
2006-04-17  0:06 ` Jon Harrop
2006-04-17  9:36   ` Christian Stork
2006-04-17 17:07     ` Jon Harrop
2006-04-18  3:25       ` Jonathan Roewen
2006-04-18  8:58       ` Christian Stork
2006-04-18 16:15         ` Christian Stork
2006-04-20 11:53     ` Damien Doligez
2006-04-17  6:50 ` Li-Thiao-Té Sébastien
2006-04-17 11:26   ` Nils Gesbert [this message]
2006-04-17 13:09 ` Xavier Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060417132607.e9dc2ad7.nils.gesbert@ens.fr \
    --to=nils.gesbert@ens.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).