Am Freitag, den 04.07.2014, 17:01 -0400 schrieb Markus Mottl: > I agree that the new concept has some noteworthy downsides as > demonstrated in the Lexing-example. Your proposed solution 2 > (stringlike) would probably solve these issues from a safety point of > view. The downside is that the complexity of string-handling would > increase even more, because then we would have three types to deal > with. I personally prefer safety over convenience, but other people's > (especially beginner's) mileage may vary. Well, the complexity can be reduced a bit by using phantom types: type string = [`String] stringlike type bytes = [`Bytes] stringlike and then just define function-by-function what is permitted: val get : 'a stringlike -> int -> char val set : [`Bytes] stringlike -> int -> char -> unit val sub : 'a stringlike -> int -> int -> [`String] stringlike val sub_bytes : 'a stringlike -> int -> int -> [`Bytes] stringlike etc., and the modules String and Bytes would just contain aliases of these functions with monomorphed typing. I don't know, though, whether we can be safe to never see the polymorphic typing when just using string and bytes. It would be a bit surprising for beginners to see that, and you sometimes would have to deal with unresolved type variables. > The Bigarray-approach doesn't seem appealing to me. Strings are much > more lightweight, since they can be allocated cheaply on the > OCaml-heap. E.g. String.create is about 10x-100x faster than > Bigarray.create. That seems too big to ignore. Oh, we ignore already that Unix.read and Unix.write copy all data through an additional buffer because we cannot pass an OCaml string directly to the OS while another thread could relocate this string. So that copy would be eliminated. So I'd guess you are normally even faster with bigarrays, at least when you only look at the use as I/O buffers. But there might be other uses where this is different. Gerd > > Regards, > Markus > > On Fri, Jul 4, 2014 at 3:18 PM, Gerd Stolpmann wrote: > > Hi list, > > > > I've just posted a blog article where I criticize the new concept of > > immutable strings that will be available in OCaml 4.02 (as option): > > > > http://blog.camlcity.org/blog/bytes1.html > > > > In short my point is that it the new concept is not far reaching enough, > > and will even have negative impact on the code quality when it is not > > improved. I also present three ideas how to improve it. > > > > Gerd > > -- > > ------------------------------------------------------------ > > Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de > > My OCaml site: http://www.camlcity.org > > Contact details: http://www.camlcity.org/contact.html > > Company homepage: http://www.gerd-stolpmann.de > > ------------------------------------------------------------ > > > > > > > > -- > > Caml-list mailing list. Subscription management and archives: > > https://sympa.inria.fr/sympa/arc/caml-list > > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > > Bug reports: http://caml.inria.fr/bin/caml-bugs > > > > -- > Markus Mottl http://www.ocaml.info markus.mottl@gmail.com > -- ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de My OCaml site: http://www.camlcity.org Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------