RE: [Caml-list] surprised by string_of_bool
> Perhaps this has been discussed before, but I found this to be disturbing. http://caml.inria.fr/pub/ml-archives/caml-list/2007/06/bfd46e630ef150536b616 debe927384b.en.html on this and also http://caml.inria.fr/pub/ml-archives/caml-list/2006/05/8158dd9e9581137f4bbcb 551e3ca6f3e.en.html on immutable strings in ocaml. > It seems easy enough to fix this problem, so that, for example, > print_string (string_of_bool true) always does the same thing. It depends on whether you regard it as a problem! IMHO if you write code that uses string mutation then you should be fully aware of where the allocation of the string that you're altering took place, just as you would with a buffer in C. If you're writing a library and are paranoid about string literals being altered then you just have to String.copy everything (I've used that before e.g. for the ocaml FFI in an ocaml-based interpreter for a language that has immutable strings only). The cost of having literal values freshly allocated on each function call (i.e. inserting String.copy before every non-format string literal) is a painful penalty for functional code that doesn't mutate strings. > The "correct" strategy seems to be used for string_of_float infinity: Well, it's just that string_of_bool can only return two possible values where string_of_float must perform an allocation each time. The declaration let string_of_bool x = String.copy (string_of_bool x);; would "fix" this function for you. David ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] surprised by string_of_bool
On Wednesday 28 May 2008 09:02:52 David Allsopp wrote: > > The "correct" strategy seems to be used for string_of_float infinity: > > Well, it's just that string_of_bool can only return two possible values > where string_of_float must perform an allocation each time. The current implementation of string_of_float happens to allocate in this case but that is not necessary. It could just as well special case these special values and return static strings. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Re: Where's my non-classical shared memory concurrency technology?
On 2008-05-27, at 11:34, Martin Berger wrote: Here I disagree. Shared memory concurrency is a specific form of message passing: Writing to a memory cell is in fact sending a message to that cell carrying two items, the new value and a return channel that is used to inform the writer that sending has succeeded, and likewise for reading. [...] But broadcasting is a form of message-passing too! That wasn't my point. My point was that there is no return channel. If you want to know when your write is done, you have to use a lock or a memory barrier. Both are very expensive. -- Damien ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Re: Where's my non-classical shared memory concurrency technology?
On Wednesday 28 May 2008 12:18:37 Damien Doligez wrote: > On 2008-05-27, at 11:34, Martin Berger wrote: > >>> Here I disagree. Shared memory concurrency is a specific form > >>> of message passing: Writing to a memory cell is in fact sending > >>> a message to that cell carrying two items, the new value and a > >>> return channel that is used to inform the writer that sending > >>> has succeeded, and likewise for reading. > > [...] > > > But broadcasting is a form of message-passing too! > > That wasn't my point. My point was that there is no return channel. > If you want to know when your write is done, you have to use a lock > or a memory barrier. Both are very expensive. Very expensive compared to what? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Re: Where's my non-classical shared memory concurrency technology?
But broadcasting is a form of message-passing too! That wasn't my point. My point was that there is no return channel. If you want to know when your write is done, you have to use a lock or a memory barrier. Both are very expensive. As I said, it's a matter of abstraction level. My point is: you can model both abstraction levels with message passing. Moreover, using shared memory doesn't magically make these synchronisation issues go away. They remain. Martin ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
[Caml-list] on objects, equality and playing nicely with the stdlib
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello list, Recently, in building some toy games, I've started using objects. I've been pleased with them and often find the subtyping convenient. However, I've run into some issues with the standard physical equality of objects that the (=) operator performs. Namely, it makes several stdlib modules difficult to use. Modules that provides a polymorphic (generic) interface such as Hashtbl, List, Stack, etc.. rely on the (=) operator. This is fine as long as it happens to be what I need. The minute I introduce my own equality however, things break down. What is the best way to go about using the stdlib (or similar) when you have your own equality function? This problem almost never shows up if you just stick with basic data types, but with objects you quickly run into it. Thanks in advance, Peng -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFIPjYcfIRcEFL/JewRAlkvAKCYjJhIc5dw5YMiwUS02LR8RowsDQCgzzAI gpif0G1fWn0vlCzzaoalWa4= =+0ZK -END PGP SIGNATURE- ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs