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 B3F9ABB84 for ; Tue, 18 Apr 2006 18:14:37 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k3IGEbJ5023678 for ; Tue, 18 Apr 2006 18:14:37 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA19178 for ; Tue, 18 Apr 2006 18:14:36 +0200 (MET DST) Received: from anthony.ics.uci.edu (anthony.ics.uci.edu [128.200.39.241]) by concorde.inria.fr (8.13.0/8.13.0) with SMTP id k3IGEZLs023672 for ; Tue, 18 Apr 2006 18:14:36 +0200 Received: (qmail 25752 invoked by uid 1000); 18 Apr 2006 16:15:35 -0000 Date: Tue, 18 Apr 2006 09:15:35 -0700 From: Christian Stork To: Jon Harrop , caml-list@inria.fr Subject: Re: [Caml-list] recursion/iterator question Message-ID: <20060418161535.GA25695@anthony.ics.uci.edu> Mail-Followup-To: Jon Harrop , caml-list@inria.fr References: <1145221898.16349.259200911@webmail.messagingengine.com> <200604170106.23660.jon@ffconsultancy.com> <20060417093635.GB13523@anthony.ics.uci.edu> <200604171807.47687.jon@ffconsultancy.com> <20060418085825.GD21750@anthony.ics.uci.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060418085825.GD21750@anthony.ics.uci.edu> X-Archive: encrypt User-Agent: Mutt/1.5.11 X-Miltered: at concorde with ID 4445106D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4445106B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; recursion:01 iterator:01 rec:01 ocaml:01 compiler:01 2006:98 2006:98 806:98 021:98 wrote:01 wrote:01 caml-list:01 complains:01 matched:01 short:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Tue, Apr 18, 2006 at 01:58:25AM -0700, Christian Stork wrote: > On Mon, Apr 17, 2006 at 06:07:47PM +0100, Jon Harrop wrote: > > On Monday 17 April 2006 10:36, Christian Stork wrote: > > > Or, if you choose to represent triplets as lists of three elements, you can > > > generalize Jon's solution to > > > let rec combs = function > > > | (0, _) -> [[]] > > > | (n, es) when n > List.length es -> [] > > > | (n, e::es) -> List.map (fun l -> e::l) (combs (n-1, es)) @ combs > > > | (n, es) > > > let triplets es = combs (3, es) > > > Question to the rest of the list: The ocaml compiler complains with > > > ... > > > Warning P: this pattern-matching is not exhaustive. > > > Here is an example of a value that is not matched: > > > (1, []) > > > (However, some guarded clause may match this value.) > > > ... > > > Am I right to assume there's no way to get rid of this warning short of > > > disabling P-warnings on the command line? (I can't list all the lacking > > > patterns since they depend on n, right?) > > The lacking patterns are covered by (_, []), so you probably want: > > | 0, _ | _, [] -> [[]] Oh, I think you meant | 0, _ -> [[]] | _, [] -> [] and that does indeed work (tho it's less efficient). -- Chris Stork <> Support eff.org! <> http://www.ics.uci.edu/~cstork/ OpenPGP fingerprint: B08B 602C C806 C492 D069 021E 41F3 8C8D 50F9 CA2F