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 QAA18494; Fri, 9 Apr 2004 16:47: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 QAA19711 for ; Fri, 9 Apr 2004 16:47:45 +0200 (MET DST) From: fis@wiwi.hu-berlin.de Received: from miro.wiwi.hu-berlin.de (miro.wiwi.hu-berlin.de [141.20.103.80]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i39Emejq000485 for ; Fri, 9 Apr 2004 16:48:40 +0200 Received: from mini (miro [141.20.103.80]) by miro.wiwi.hu-berlin.de (8.11.7+Sun/8.8.6) with ESMTP id i39Elh104156 for ; Fri, 9 Apr 2004 16:47:44 +0200 (MET DST) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16502.46797.938811.422113@gargle.gargle.HOWL> Date: Fri, 9 Apr 2004 16:44:29 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] String.map => Question to the OCaml-team In-Reply-To: <16502.42309.605598.795600@gargle.gargle.HOWL> References: <20040409110138.GA1333@first.in-berlin.de> <16502.38522.179048.194250@gargle.gargle.HOWL> <16502.42309.605598.795600@gargle.gargle.HOWL> X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ocaml-team:01 filliatre:01 filliatre:01 lri:01 2004:99 caml-list:01 ocaml-team:01 char:01 char:01 incr:01 for':99 matthias:01 compiler:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 217 Jean-Christophe Filliatre writes: > From: Jean-Christophe Filliatre > Date: Fri, 9 Apr 2004 15:29:41 +0200 > Subject: Re: [Caml-list] String.map => Question to the OCaml-team > > > > 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: I dislike loops... (-: But I am an idiot. In this case, a loop is not only closer to how a CPU thinks but also leads to a more elegant representation of the algorithm. I assume that one reason why the loop is faster is the additional reference cell access operations in my code. (I still think there is some way of compiling away the reference in this particular example using very general compiler patterns. Not sure, though. Perhaps I am still an idiot.) matthias ------------------- 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