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 PAA13820; Fri, 9 Apr 2004 15:38:29 +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 PAA14227 for ; Fri, 9 Apr 2004 15:38:28 +0200 (MET DST) Received: from lri.lri.fr (lri.lri.fr [129.175.15.1]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i39DcRYM010437 for ; Fri, 9 Apr 2004 15:38:27 +0200 Received: from pc8-123 (pc8-123 [129.175.8.123]) by lri.lri.fr (8.12.10/jtpda-5.4) with ESMTP id i39DTgCr012634 ; Fri, 9 Apr 2004 15:29:42 +0200 (MEST) Received: from filliatr by pc8-123 with local (Exim 3.35 #1 (Debian)) id 1BBw4j-0007tT-00; Fri, 09 Apr 2004 15:29:41 +0200 From: Jean-Christophe Filliatre MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16502.42309.605598.795600@gargle.gargle.HOWL> Date: Fri, 9 Apr 2004 15:29:41 +0200 To: fis@wiwi.hu-berlin.de, oliver@first.in-berlin.de (Oliver Bandel) CC: caml-list@inria.fr Subject: Re: [Caml-list] String.map => Question to the OCaml-team In-Reply-To: <16502.38522.179048.194250@gargle.gargle.HOWL> References: <20040409110138.GA1333@first.in-berlin.de> <16502.38522.179048.194250@gargle.gargle.HOWL> X-Mailer: VM 7.03 under Emacs 20.7.2 Reply-To: Jean-Christophe.Filliatre@lri.fr (Jean-Christophe Filliatre) X-MailScanner: Found to be clean X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; filliatre:01 filliatr:01 lri:01 caml-list:01 ocaml-team:01 char:01 char:01 incr:01 for':99 ocaml:01 ocaml:01 string:03 string:03 slightly:03 iter:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 214 > I don't know much about ocaml, but my bet is the implementation of > strings doens't allow for anything considerably more efficient than > this: > > let string_map (f: char -> char) (s: string) : string = > let t = String.copy s in > let i = ref 0 in > String.iter (fun c -> let d = f c in String.set t !i d; incr i) s; > t;; Note there is a `for' construct in ocaml: ====================================================================== let string_map (f: char -> char) (s: string) : string = let t = String.copy s in for i = 0 to String.length s - 1 do t.[i] <- f s.[i] done; t ====================================================================== and this is slightly faster than your implementation (by 10%). -- Jean-Christophe ------------------- 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