From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA11071; Sun, 10 Aug 2003 21:54:24 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 VAA11275 for ; Sun, 10 Aug 2003 21:54:23 +0200 (MET DST) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h7AJsLf24460 for ; Sun, 10 Aug 2003 21:54:21 +0200 (MET DST) Received: (qmail 27580 invoked by uid 566); 10 Aug 2003 19:54:18 -0000 Date: Sun, 10 Aug 2003 21:53:07 +0200 From: Michal Moskal To: caml-list@inria.fr Subject: Re: [Caml-list] Array.filter (was Multi-keyed lookup table?) Message-ID: <20030810195307.GA19113@roke.freak> Mail-Followup-To: caml-list@inria.fr References: <005d01c35e51$7c927200$6628f9c1@zofo> <20030809165720.GE21525@swordfish> <20030809184851.GA946@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030809184851.GA946@localhost> User-Agent: Mutt/1.4.1i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; michal:01 moskal:01 malekith:01 pld-linux:01 caml-list:01 ijtrotts:01 struct:01 kernel:01 0700,:01 int:01 ucdavis:02 module:03 gcs:03 wrote:03 obj:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, Aug 09, 2003 at 11:48:51AM -0700, ijtrotts@ucdavis.edu wrote: > # module Array = struct > include Array > let filter f a = Array.init (Array.length a) (fun i -> f a.(i)) > end;; > # Array.filter (fun x -> x * x) [| 1;2;3 |];; > - : int array = [|1; 4; 9|] This is map, not filter. Writing filter is more difficult, since you need to first make list of results and then put them into array (or use Obj.magic tricks). -- : Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv : When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners