From: oleg@okmij.org
To: gabriel.scherer@gmail.com
Cc: goswin-v-b@web.de, caml-list@inria.fr
Subject: Re: [Caml-list] Why List.map does not be implemented
Date: Tue, 30 Sep 2014 04:46:41 -0400 (EDT) [thread overview]
Message-ID: <20140930084641.1FFBAC3825@www1.g3.pair.com> (raw)
In-Reply-To: <CAPFanBHFO_t3N+f2hTZ+hytEj=8fhBAik-PYFcrcn2VayJ+dvw@mail.gmail.com>
Gabriel Scherer wrote
> it is safe to Obj.magic a mutable data-structure into an immutable
> one. The Obj.magic-using code for List.map, implemented in Extlib and
> inherited by Batteries, is careful to use an unsafe cast in exactly
> the second situation. This is a feature that other languages
> (eg. Mezzo) safely provide.
Let me relay a short anecdote about the List.map function in
Batteries. Once I received a message from a person who was using the
Hansei library of probabilistic programming. He reported a problem:
his program produced clearly wrong results. He even traced the problem
to the function 'List.map' -- saying that if he wrote List.map himself,
the problem disappeared. I was initially puzzled: how one can possibly
mis-write List.map. I asked for more details and he said that he was
using Batteries. That gave me a hunch: I went to the Battery
repository to look at the source code and found what I expected --
mutation. In probabilistic programs, mutation has to be done
carefully. Mutation to the global heap forces correlation on what
should be independent ``possible worlds''. Mutation has to be done
with world-local heaps, which Hansei provides for that purpose. There
are times when hidden optimizations come to bite us.
I guess in Mezzo I would have seen from the type that a mutation is
performed, and would have avoided the optimized Map (or the type
checker would make me avoid it).
next prev parent reply other threads:[~2014-09-30 8:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-28 19:31 [Caml-list] Why List.map does not be implemented tail-recursively? Shuai Wang
2014-09-28 19:36 ` Gabriel Scherer
2014-09-28 19:45 ` Anthony Tavener
2014-09-29 12:08 ` Goswin von Brederlow
2014-09-29 14:02 ` Pierre Chambart
2014-09-29 15:44 ` Yaron Minsky
2014-09-29 21:00 ` Gabriel Scherer
2014-09-30 8:46 ` oleg [this message]
2014-09-30 9:07 ` [Caml-list] Why List.map does not be implemented Gabriel Scherer
2014-10-01 10:29 ` oleg
2014-10-01 12:00 ` Gerd Stolpmann
2014-10-29 10:11 ` Gabriel Scherer
2014-10-02 10:09 ` [Caml-list] Why List.map does not be implemented tail-recursively? Stephen Dolan
2015-06-01 12:02 ` Jon Harrop
2015-06-02 12:04 ` Stephen Dolan
2015-06-05 10:21 ` Goswin von Brederlow
2014-09-30 6:29 ` Goswin von Brederlow
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=20140930084641.1FFBAC3825@www1.g3.pair.com \
--to=oleg@okmij.org \
--cc=caml-list@inria.fr \
--cc=gabriel.scherer@gmail.com \
--cc=goswin-v-b@web.de \
/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