caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
To: "Stéphane Baubillier" <sbaubillier@pactenovation.fr>
Cc: <tech@diffusionnet.com>, <caml-list@inria.fr>
Subject: Re: [Caml-list] crible d'eratosthene
Date: Wed, 25 Apr 2001 09:02:59 +0200 (MEST)	[thread overview]
Message-ID: <15078.30371.456286.292131@pc803> (raw)
In-Reply-To: <005801c0b48c$d545b3b0$290000c0@pactenovation.fr>


Just a  minor remark: it is  more natural (and more  concise) to write
Eratosthene's  sieve using  Ocaml streams  and their  lazy evaluation,
like this

======================================================================
let rec filter p = parser
  [< 'n; s >] -> if p n then [< 'n; filter p s >] else [< filter p s >]

let naturals = 
  let rec gen n = [< 'n; gen (succ n) >] in gen 2

let primes =
  let rec sieve = parser
    [< 'n; s >] -> [< 'n; sieve (filter (fun m -> m mod n <> 0) s) >]
  in
  sieve naturals
======================================================================

-- 
Jean-Christophe FILLIATRE
  mailto:Jean-Christophe.Filliatre@lri.fr
  http://www.lri.fr/~filliatr


=?iso-8859-1?Q?St=E9phane_Baubillier?= writes:
 > Here is an example :
 > 
 > http://caml.inria.fr/Examples/cl/basics/sieve.ml
 > 
 > Stephane Baubillier
 > Pacte Novation
 > 
 > ----- Original Message -----
 > From: <tech@diffusionnet.com>
 > To: <caml-list@inria.fr>
 > Sent: Tuesday, April 24, 2001 3:29 PM
 > Subject: [Caml-list] crible d'eratosthene
 > 
 > 
 > 
 > Bonjour,
 > 
 > Je suis nouveau ici et en apprentissage sur le langage CAML.
 > 
 > Je suis à la recherche d'un exemple très simple utilisant que des fonctions
 > de base (listes, pas de boucle) recursivité, concernant le crible
 > d'eratosthene. J'ai trouvé sur le net des exemples mais rien d'assez simple.
 > 
 > Exemple en clair:
 > 
 > J'ai une liste [1;2;3;4;5;6;7;8;9;10;11;12]
 > une liste vide qui doit contenir les nombres premiers.
 > 
 > 1/ On extrait la tete de la liste (2) pour l'ajouter à la liste des nombres
 > premiers (initialement vide)
 > 2/ On supprime de la liste des nombres tous les multiples du nombre extrait
 > lors de l'étape 1
 > 3/ On recommence les étapes 1 et 2 jusqu'à obtention d'une liste vide.
 > 
 > Si qq peut me faire parvenir un source rapidement, je lui en serait très
 > reconnaissant !!!
 > 
 > Cordialement
 > 
 > CP.
 > 
 > -------------------
 > To unsubscribe, mail caml-list-request@inria.fr.  Archives:
 > http://caml.inria.fr
 > 
 > -------------------
 > To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


      reply	other threads:[~2001-04-25  7:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-24 15:29 tech
2001-03-24 18:04 ` Stéphane Baubillier
2001-04-25  7:02   ` Jean-Christophe Filliatre [this message]

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=15078.30371.456286.292131@pc803 \
    --to=jean-christophe.filliatre@lri.fr \
    --cc=caml-list@inria.fr \
    --cc=sbaubillier@pactenovation.fr \
    --cc=tech@diffusionnet.com \
    /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).