* Not really a bug but...
@ 2007-06-16 0:17 Jon Harrop
2007-06-16 7:30 ` [Caml-list] " Alain Frisch
0 siblings, 1 reply; 7+ messages in thread
From: Jon Harrop @ 2007-06-16 0:17 UTC (permalink / raw)
To: caml-list
Any chance of changing the semantics of string literals so they aren't static?
# let f() = "a";;
val f : unit -> string = <fun>
# let s = f();;
val s : string = "a"
# s.[0] <- 'b';;
- : unit = ()
# f();;
- : string = "b"
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Not really a bug but...
2007-06-16 0:17 Not really a bug but Jon Harrop
@ 2007-06-16 7:30 ` Alain Frisch
2007-06-16 10:02 ` Christophe TROESTLER
2007-06-16 10:10 ` Loup Vaillant
0 siblings, 2 replies; 7+ messages in thread
From: Alain Frisch @ 2007-06-16 7:30 UTC (permalink / raw)
To: Jon Harrop; +Cc: caml-list
Jon Harrop wrote:
> Any chance of changing the semantics of string literals so they aren't static?
A simple Camlp4 syntax extension is enough to turn any literal "foobar"
into String.copy "foobar". (Except it doesn't work because of format
strings.) If it were done automatically, there would be a penalty for
the common case of immutable strings; to avoid it, you'd need to lift
constant literals out of abstractions, which is not very nice.
-- Alain
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Not really a bug but...
2007-06-16 7:30 ` [Caml-list] " Alain Frisch
@ 2007-06-16 10:02 ` Christophe TROESTLER
2007-06-16 10:10 ` Loup Vaillant
1 sibling, 0 replies; 7+ messages in thread
From: Christophe TROESTLER @ 2007-06-16 10:02 UTC (permalink / raw)
To: caml-list
On Sat, 16 Jun 2007, Alain Frisch <Alain.Frisch@inria.fr> wrote:
>
> Jon Harrop wrote:
> > Any chance of changing the semantics of string literals so they aren't static?
>
> A simple Camlp4 syntax extension is enough to turn any literal "foobar"
> into String.copy "foobar". (Except it doesn't work because of format
> strings.) If it were done automatically, there would be a penalty for
> the common case of immutable strings; to avoid it, you'd need to lift
> constant literals out of abstractions, which is not very nice.
As a side question, any chance of seeing a compiler flag to treat
strings in an immutable way (so as to restrict their mutability to
some modules only)?
ChriS
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Not really a bug but...
2007-06-16 7:30 ` [Caml-list] " Alain Frisch
2007-06-16 10:02 ` Christophe TROESTLER
@ 2007-06-16 10:10 ` Loup Vaillant
2007-06-16 15:59 ` Richard Jones
2007-06-16 17:01 ` skaller
1 sibling, 2 replies; 7+ messages in thread
From: Loup Vaillant @ 2007-06-16 10:10 UTC (permalink / raw)
To: caml-list
2007/6/16, Alain Frisch <Alain.Frisch@inria.fr>:
> Jon Harrop wrote:
> > Any chance of changing the semantics of string literals so they aren't static?
> [...]
> If it were done automatically, there would be a penalty for
> the common case of immutable strings; to avoid it, you'd need to lift
> constant literals out of abstractions, which is not very nice.
By the way, why Ocaml didn't take the Java path, i.e. making truly
immutable strings, And provide mutable string buffers as well? Any
chance of seing someone exploring that path? (Some usefull features
would then be fast consing and catenation, and some easier string
sharing).
Loup
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Not really a bug but...
2007-06-16 10:10 ` Loup Vaillant
@ 2007-06-16 15:59 ` Richard Jones
2007-06-16 17:01 ` skaller
1 sibling, 0 replies; 7+ messages in thread
From: Richard Jones @ 2007-06-16 15:59 UTC (permalink / raw)
To: Loup Vaillant; +Cc: caml-list
On Sat, Jun 16, 2007 at 12:10:35PM +0200, Loup Vaillant wrote:
> 2007/6/16, Alain Frisch <Alain.Frisch@inria.fr>:
> >Jon Harrop wrote:
> >> Any chance of changing the semantics of string literals so they aren't
> >static?
> >[...]
> >If it were done automatically, there would be a penalty for
> >the common case of immutable strings; to avoid it, you'd need to lift
> >constant literals out of abstractions, which is not very nice.
>
> By the way, why Ocaml didn't take the Java path, i.e. making truly
> immutable strings, And provide mutable string buffers as well? Any
> chance of seing someone exploring that path? (Some usefull features
> would then be fast consing and catenation, and some easier string
> sharing).
Mutable strings are useful! - I can use them as bitfields, general
data areas (for ioctl, mlock), etc See:
http://et.redhat.com/~rjones/hvcalls/
Rich.
--
Richard Jones
Red Hat
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Not really a bug but...
2007-06-16 10:10 ` Loup Vaillant
2007-06-16 15:59 ` Richard Jones
@ 2007-06-16 17:01 ` skaller
2007-06-16 17:03 ` Jon Harrop
1 sibling, 1 reply; 7+ messages in thread
From: skaller @ 2007-06-16 17:01 UTC (permalink / raw)
To: Loup Vaillant; +Cc: caml-list
On Sat, 2007-06-16 at 12:10 +0200, Loup Vaillant wrote:
> 2007/6/16, Alain Frisch <Alain.Frisch@inria.fr>:
> > Jon Harrop wrote:
> > > Any chance of changing the semantics of string literals so they aren't static?
> > [...]
> > If it were done automatically, there would be a penalty for
> > the common case of immutable strings; to avoid it, you'd need to lift
> > constant literals out of abstractions, which is not very nice.
>
> By the way, why Ocaml didn't take the Java path, i.e. making truly
> immutable strings, And provide mutable string buffers as well?
It didn't because it didn't .. :)
Strings are mutable because they can be, without impacting
the run time/garbage collector: Ocam's razor says use
one type when it will do the work of two.
It's unfortunate that in the abstract, Ocaml string are
entirely the worst possible multi-function data type as a result,
since they neither offer the advantages of immutability nor the
advantages of being variable length: mutable fixed length strings
are almost useless .. but not entirely: they're still useful as I/O
buffers.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Not really a bug but...
2007-06-16 17:01 ` skaller
@ 2007-06-16 17:03 ` Jon Harrop
0 siblings, 0 replies; 7+ messages in thread
From: Jon Harrop @ 2007-06-16 17:03 UTC (permalink / raw)
To: caml-list
On Saturday 16 June 2007 18:01:21 skaller wrote:
> mutable fixed length strings
> are almost useless .. but not entirely: they're still useful as I/O
> buffers.
Like Richard, I use fixed-length mutable strings quite a lot. This complicated
the translation of some programs to F# which only provides immutable (but
unicode) strings.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-06-16 17:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-16 0:17 Not really a bug but Jon Harrop
2007-06-16 7:30 ` [Caml-list] " Alain Frisch
2007-06-16 10:02 ` Christophe TROESTLER
2007-06-16 10:10 ` Loup Vaillant
2007-06-16 15:59 ` Richard Jones
2007-06-16 17:01 ` skaller
2007-06-16 17:03 ` Jon Harrop
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox