From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Markus Mottl <mottl@miss.wu-wien.ac.at>,
Pierre Weis <Pierre.Weis@inria.fr>
Cc: OCAML <caml-list@inria.fr>
Subject: Re: cyclic value construction ("let rec")
Date: Thu, 6 Apr 2000 16:25:52 +0200 [thread overview]
Message-ID: <20000406162552.49765@pauillac.inria.fr> (raw)
In-Reply-To: <200004061334.PAA18159@miss.wu-wien.ac.at>; from Markus Mottl on Thu, Apr 06, 2000 at 03:34:18PM +0200
> > [Pierre Weis:]
> > This certainly suggests to allow the export of an immutable view of a
> > record type with mutable fields. This way you could do the
> > initialization in a safe way (no magic) using side effects, and still
> > export a safe immutable type to the external world.
>
> [Markus Mottl:]
> Sounds like a good idea! Using powerful "magic" is probably too dangerous
> for "everyday"-use and definitely not in accordance with the "zero defect"
> ambitions of the type system...
> Although it would sometimes be nice to even hide specific fields of the
> record, this would probably not work well together with separate
> compilation. However, the memory layout of the fields does not change by
> just omitting the "mutable" declaration, so this should not do any harm.
Alas, it can do a lot of harm. For one thing, you could break type
safety this way, just like with polymorphic references:
A.ml:
type 'a t = { mutable contents: 'a }
let assign t v = t.contents <- v
A.mli:
type 'a t = { contents: 'a}
val assign: 'a t -> 'a -> unit
Client.ml:
open A
...
let x = { contents = [] } in
assign x [1];
x.contents = [true]
When typing Client.ml, since "contents" is assumed immutable, the
definition of x is a syntactic value, hence x receives type
forall 'a. 'a list t
But of course this typing is invalidated by the call to "assign",
and you end up comparing an int list to a bool list -- a typing violation.
Some compiler optimisations, specific to immutable structures, could
similarly be broken.
So, no, we can't allow exporting a record with different mutability
annotations than in its definition.
- Xavier Leroy
next prev parent reply other threads:[~2000-04-09 23:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-03-30 20:12 Benoit Deboursetty
2000-04-03 12:57 ` Markus Mottl
2000-04-06 13:18 ` Pierre Weis
2000-04-06 13:34 ` Markus Mottl
2000-04-06 14:25 ` Xavier Leroy [this message]
2000-04-06 15:12 ` Markus Mottl
2000-04-10 0:03 ` Pierre Weis
2000-04-10 1:41 ` Markus Mottl
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=20000406162552.49765@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=Pierre.Weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=mottl@miss.wu-wien.ac.at \
/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