Browse thread
[Caml-list] String.map => Question to the OCaml-team
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | fis@w... |
| Subject: | Re: [Caml-list] String.map => Question to the OCaml-team |
Jean-Christophe Filliatre writes: > From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr> > 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