From: Stephan Houben <stephan@pcrm.win.tue.nl>
To: Chris Hecker <checker@d6.com>
Cc: caml-list@inria.fr
Subject: Re: practical functional programming
Date: Thu, 9 Nov 2000 11:56:05 +0100 [thread overview]
Message-ID: <00110912094400.16244@pcrm> (raw)
In-Reply-To: <4.3.2.7.2.20001107021125.00acbcd0@shell16.ba.best.com>
On Tue, 07 Nov 2000, Chris Hecker wrote:
> How does the compiler "know" the datastructure is purely functional?
It doesn't. Why would it have to?
> In other words, is there any way for me to get a type into a tree that has a
> mutable member (perhaps through an abstract type),
Yes there is. You can make a map that contains, for example,
values of type `int ref' or `int array'.
> and if so, what happens in
> that case?
Well, as you already might know, O'Caml *never* copies anything unless
you explicitely tell it to. For example, the following session:
# let ar1 = [|1|];;
val ar1 : int arr# ar1.(0) <- # ar2;;
- : int array = [|2|]2;;
- : unit = () ay = [|1|]
# let ar2 = ar1;;
val ar2 : int array = [|1|]
# ar2;;
- : int array = [|1|]
# ar1.(0) <- 2;;
- : unit = ()
# ar2;;
- : int array = [|2|]
So I mutated ar1, but the update is reflected in ar2. In C++ speech, all
variables are implicitely "references" to the underlying object. ar1 and ar2
refer to the same object. If you want ar2 to be a new array, then you
have to use Array.copy to explicitely tell O'Caml that you want a new
array.
So yes, if I have a map map1, and I get an "updated" map2 from that, then
mutations to the objects held in map1 will be reflected in map2.
Stephan
--
ir. Stephan H.M.J. Houben
tel. +31-40-2474358 / +31-40-2743497
e-mail: stephanh@win.tue.nl
next prev parent reply other threads:[~2000-11-09 18:06 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-11-03 22:44 Chris Hecker
2000-11-04 18:48 ` Chet Murthy
2000-11-05 14:25 ` John Max Skaller
2000-11-06 22:26 ` Michael Hicks
2000-11-06 6:55 ` Francisco Reyes
2000-11-06 13:16 ` Jean-Christophe Filliatre
2000-11-06 18:15 ` Chris Hecker
2000-11-07 7:54 ` Stephan Houben
2000-11-11 14:32 ` John Max Skaller
2000-11-12 13:17 ` Ken Wakita
2000-11-12 20:09 ` John Max Skaller
2000-11-13 0:19 ` Ken Wakita
2000-11-13 7:45 ` STARYNKEVITCH Basile
2000-11-07 9:06 ` Xavier Leroy
2000-11-07 10:13 ` Chris Hecker
2000-11-09 10:56 ` Stephan Houben [this message]
2000-11-09 21:56 ` Chris Hecker
2000-11-07 18:05 ` Thorsten Ohl
2000-11-07 19:19 ` Marcin 'Qrczak' Kowalczyk
2000-11-06 23:10 Hao-yang Wang
2000-11-06 23:24 Hao-yang 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=00110912094400.16244@pcrm \
--to=stephan@pcrm.win.tue.nl \
--cc=caml-list@inria.fr \
--cc=checker@d6.com \
--cc=stephanh@win.tue.nl \
/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;
as well as URLs for NNTP newsgroup(s).