From: "ivan chollet" <ivan.chollet@free.fr>
To: "'Edgar Friendly'" <thelema314@gmail.com>
Cc: <caml-list@yquem.inria.fr>
Subject: RE: [Caml-list] ocaml sefault in bytecode: unanswered questions
Date: Sat, 8 Aug 2009 16:15:44 +0200 [thread overview]
Message-ID: <000001ca1832$b950eb80$2bf2c280$@chollet@free.fr> (raw)
In-Reply-To: <4A7D7DAF.6070904@gmail.com>
Yes, makes sense. But it would mean that "List.iter myfun !myref" is not semantically equivalent to "List.iter myfun (let l=!myref in l)", therefore the expressions "let l=!myref in l" and "!myref" are not semantically equivalent.
That would be very strange!
-----Original Message-----
From: Edgar Friendly [mailto:thelema314@gmail.com]
Sent: samedi 8 août 2009 15:29
To: ivan chollet
Cc: 'Cedric Auger'; caml-list@yquem.inria.fr
Subject: Re: [Caml-list] ocaml sefault in bytecode: unanswered questions
ivan chollet wrote:
> You basically state that stuff like “let l = !myref in List.iter myfun l”
> (where myfun modifies !myref) wouldn't produce segfault.
> Why? It would mean that doing "let l = !myref" creates a brand new OCaml
> entity, l, ie a brand new allocation on the heap, and then, messing around
> with !myref inside myfun would be of course 100% safe. Is that what OCaml
> runtime does?
when you have [myref : list ref = ref [1;2]], this is in memory as:
myref -> {contents: _a}
_a -> (1,_b)
_b -> (2,0)
I've given names to the intermediate pointers -- the notation above
shows names as pointers to data structures. [myref] is a pointer to a
record, whose contents point to the head of the list [1;2]. So there's
already two levels of indirection.
When you do [let l = !myref], [l] gets assigned [_a], so it points to
the head of the list. List.iter traverses the list not even knowing
that [myref] exists, so if the function [myfun] modifies [myref], it
won't affect List.iter.
Does this make sense?
E
next prev parent reply other threads:[~2009-08-08 14:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-08 9:17 ivan chollet
2009-08-08 13:29 ` Edgar Friendly
2009-08-08 14:15 ` ivan chollet [this message]
2009-08-08 17:14 ` David Allsopp
2009-08-09 1:45 ` ivan chollet
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='000001ca1832$b950eb80$2bf2c280$@chollet@free.fr' \
--to=ivan.chollet@free.fr \
--cc=caml-list@yquem.inria.fr \
--cc=thelema314@gmail.com \
/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