Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] String.map => Question to the OCaml-team
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: fis@w...
Subject: [Caml-list] String.map => Question to the OCaml-team


> it's nice to have a String.iter, but more functional would
> be to have a String.map function.

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;;

to test, type:

let s = "a=b1";;
let t = string_map (fun c -> char_of_int (int_of_char c + 1)) s;;

Does this generate optimal code, or where not?  What are the technical
/ political procedures to put these lines into the next distribution?
Are there any good reasons against doing so?

Well, I guess there always are...  (-:

curious,
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