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 XAA14511; Sun, 10 Aug 2003 23:59:46 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA13816 for ; Sun, 10 Aug 2003 23:59:45 +0200 (MET DST) Received: from mail.exomi.com (mail.exomi.com [217.169.64.72]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h7ALxiT13896 for ; Sun, 10 Aug 2003 23:59:44 +0200 (MET DST) Received: from oxy.exomi.com (unknown [10.0.5.5]) by mail.exomi.com (Postfix) with ESMTP id BCF8A5D03 for ; Mon, 11 Aug 2003 00:59:43 +0300 (EEST) Received: by oxy.exomi.com (Postfix, from userid 501) id CA5BA380131; Mon, 11 Aug 2003 00:59:45 +0300 (EEST) Date: Mon, 11 Aug 2003 00:59:45 +0300 From: Ville-Pertti Keinonen To: caml-list@inria.fr Subject: Re: [Caml-list] Array.filter (was Multi-keyed lookup table?) Message-ID: <20030810215944.GA495@exomi.com> Mail-Followup-To: caml-list@inria.fr References: <005d01c35e51$7c927200$6628f9c1@zofo> <20030809184851.GA946@localhost> <20030810195307.GA19113@roke.freak> <200308102222.16369.qrczak@knm.org.pl> <20030810204319.GA24968@roke.freak> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030810204319.GA24968@roke.freak> User-Agent: Mutt/1.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 michal:01 moskal:01 predicate:01 sparse:01 verbose:01 ignoring:01 dynamically:01 arrays:01 bool:01 ocaml:01 lisp:01 0200,:01 side-effects:02 worse:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, Aug 10, 2003 at 10:43:19PM +0200, Michal Moskal wrote: > It will bomb for large arrays. List.filter will not (BTW I don't > understand why List.filter uses List.rev to be tail recursive and List.map > does not). > > Another thought would be to create bool array for predicate results, fill > it, counting how much space do you need, and then create result array. > > There is also third way, to run predicate twice, but it is not guaranteed > safe in presence of side effects. How about just creating a result array the same size as the original (initially filled with item 0 of the original, special-cased for empty arrays) and Array.sub:ing it for the result? I'd think that would be the obvious method. Creating new instances of a value shouldn't have any noticable side-effects. Anyway, filter for arrays as well as strings is one of the more useful things that might be desirable as part of the standard library. Functions for mapping and folding strings might also be useful. While the OCaml standard library is pretty good, it seems fairly sparse compared to e.g. the functionality offered by Common Lisp sequence functions, which work on lists, arrays and strings. Implementing the necessary functionality is easy, but an advantage of having more things as part of the standard lirbary would be the reduction in LOC for OCaml solutions to programming tasks used to compare programming languages (e.g. Prechelt's study, although that didn't include OCaml). OCaml isn't otherwise much more verbose than Common Lisp (ignoring macros) or various scripting languages, but for array and string manipulation, it can end up looking much worse than it needs to. Plenty of people who don't know many languages seem to believe that static typing and/or explicit lexical scoping inevitably make languages verbose, and that dynamically typed scripting languages with idiosyncratic scoping rules and huge performance hits are the only way around that. ------------------- 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