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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 1AA64BBBB for ; Thu, 30 Mar 2006 21:03:30 +0200 (CEST) Received: from out1.smtp.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k2UJ3T8Z029442 for ; Thu, 30 Mar 2006 21:03:29 +0200 Received: from frontend2.internal (frontend2.internal [10.202.2.151]) by frontend1.messagingengine.com (Postfix) with ESMTP id DBB9AD42F25; Thu, 30 Mar 2006 14:03:27 -0500 (EST) Received: from frontend3.messagingengine.com ([10.202.2.152]) by frontend2.internal (MEProxy); Thu, 30 Mar 2006 14:03:07 -0500 X-Sasl-enc: BhnCekh2SSFS/rOr595VvLRCSkCTfSB/T465Y4mrL0ik 1143745386 Received: from munge (burnham.ljcrf.edu [192.231.106.2]) by frontend3.messagingengine.com (Postfix) with ESMTP id 77CB71FB3; Thu, 30 Mar 2006 14:03:06 -0500 (EST) Date: Thu, 30 Mar 2006 11:02:52 -0800 (PST) From: Martin Jambon X-X-Sender: martin@munge To: Jonathan Roewen Cc: OCaml Subject: Re: [Caml-list] Feature Wish: List comprehensions In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at nez-perce with ID 442C2B81.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; camlp:01 lib:01 oandrieu:01 nerim:01 ocaml:01 ocamlfind:01 camlp:01 haskell:01 haskell:01 ocaml:01 beginner's:01 beginners:01 bug:01 wrote:01 hacks: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 There's a camlp4 lib for this: http://oandrieu.nerim.net/ocaml/#pa_compr If you use ocamlfind, you might want install it with p4ck, which also installs a few other camlp4 hacks from various authors. (http://martin.jambon.free.fr/p4ck.html) Martin On Thu, 30 Mar 2006, Jonathan Roewen wrote: > Hi, > > I'm having a small problem trying to tidily define an equivalent > function to some Haskell code. > > Haskell: > pThen combine p1 p2 toks > = [ (combine v1 v2, toks2) | (v1,toks1) <- p1 toks, (v2, toks2) <- p2 toks1 ] > > (I'll also be needing to specify equivalents for pThen3 & pThen4). > > The first isn't too bad... > > let pThen combine p1 p2 = fun ts -> > let l1 = p1 ts in > let l2 = List.map (fun (v1,ts1) -> p2 ts1) l1 in > List.concat > (List.map2 (fun (v1,ts1) l2 -> List.map (fun (v2,ts2) -> combine > v1 v2,ts2) l2) l1 l2) > > As you can see, extending this style to pThen3 & pThen4 is going to be > very, very ugly (and hard to get right first time). > > I know it's just shorthand for map/filter, (and more complex > derivatives of these), but it would be nice to have in ocaml... > > BTW: any suggestions on a better way to write the above function would > be appreciated ;-) > > Kindest Regards, > > Jonathan Roewen > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- Martin Jambon, PhD http://martin.jambon.free.fr Edit http://wikiomics.org, bioinformatics wiki