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: | Nicolas Cannasse <warplayer@f...> |
| Subject: | Re: [Caml-list] String.map => Question to the OCaml-team |
> > > 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%). > > > > Why not just use String.blit, as provided by the standard library? > > > > Fernando > > > The whole thing would be a lot nicer if there were a String.init > > init : int -> (int -> char) -> string > > obviously modeled on Array.init, since the OCaml designers had enough good > sense not to follow Haskell and make strings lists (or provide abominable > built in string -> char list functions). I wonder how usefulthis is in > typical string manipulation? I guess I find other ways to do things... > > It would of course be nice if we had the oft discussed generic polymorphism > so that we could take better advantage of the similarity of strings and arrays > (and bigarrays and hastables and ...) than we can now. Bazaar to Cathedral, > anyone home? :-) Look at ExtLib :-) we added String.init and we have Enum module which can play with String as Array of chars without actually allocating an array of chars. http://ocaml-lib.sf.net Of course generics would add more sugar into our everyday caml coffee. Regards, Nicolas Cannasse ------------------- 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