From: John Carr <jfc@mit.edu>
To: Thomas Fischbacher <t.fischbacher@soton.ac.uk>
Cc: OCaML Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Weird GC behaviour
Date: Wed, 28 Sep 2011 09:07:53 -0400 [thread overview]
Message-ID: <201109281307.p8SD7rjH023503@outgoing.mit.edu> (raw)
In-Reply-To: <4E830AC3.6020405@soton.ac.uk>
> How come (Ftag "funny") is regarded as constant while
> (Rtag (ref "funny")) is not? After all, strings are mutable in OCaml,
> so there really is not that much of a conceptual difference between a
> string and a string ref in that respect:
This is just one of the axioms of the language. A single
string literal in OCaml source code yields the same value
each time it is evaluated, even though arguably analgous
constructs are handled differently:
[1;2;3] == [1;2;3] may be true or false
[|1;2|] == [|1;2|] will be false
"const" == "const" will be false
let f () = "const" in f () == f () will be true
I would rather have identical string constants merged, as many C
compilers do. (I am aware that it is possible to write programs
with bugs.) The compiler could also treat string constants like
array constants and generate a new value each time the expression
is evaluated. In that case my last example would be false.
If you want to argue analogies, consider
let f () = F "hello"
as an alias for something like
let hello = [|'h';'e';'l';'l';'o'|] (* at top level *)
let f () = F hello
The name hello is as constant as any other top level binding.
> But the problem I think I have with OCaml is: there just seems to be no
> way to properly express the conceptual difference between '(1 2 3 4 5)
> and (list 1 2 3 4 5): All I can say above is: Ftag "Hello".
You can use Obj.dup to force a copy. I don't know whether there is
a type safe interface.
next prev parent reply other threads:[~2011-09-28 13:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-27 17:30 Thomas Fischbacher
2011-09-28 11:19 ` Damien Doligez
2011-09-28 11:53 ` Thomas Fischbacher
2011-09-28 12:12 ` Gabriel Scherer
2011-09-28 13:07 ` John Carr [this message]
2011-09-28 15:30 ` Damien Doligez
2011-09-28 23:32 ` Philippe Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201109281307.p8SD7rjH023503@outgoing.mit.edu \
--to=jfc@mit.edu \
--cc=caml-list@inria.fr \
--cc=t.fischbacher@soton.ac.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox