caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: oleg@okmij.org
Cc: Goswin von Brederlow <goswin-v-b@web.de>,
	caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Why List.map does not be implemented
Date: Tue, 30 Sep 2014 11:07:45 +0200	[thread overview]
Message-ID: <CAPFanBFyQApQX7rwkjy1PCyKqyyjuP0YauOJcnw58AFoEiyGZg@mail.gmail.com> (raw)
In-Reply-To: <20140930084641.1FFBAC3825@www1.g3.pair.com>

[-- Attachment #1: Type: text/plain, Size: 2337 bytes --]

That is an extremely interesting story that I would like to understand
better. Which pointers would you recommend to read more about mutation in
HANSEI?

My intuition would be that the mutation should not be observable in this
case, as it is only done on "private" data that the List.map function
allocate, owns, and which never escapes in its immutable form. While I
understand why mutating global data is an observable side-effect that can
play badly with any form of backtracking/probabilistic monad, I do not have
any intuition about why mutating a privately-owned heap fragment would
perturb the system. If I was pressed to make an hypothesis (while not
knowing the system), I would guess that this is because of an
implementation detail of HANSEI, not because of its actual semantic
requirements.

On Tue, Sep 30, 2014 at 10:46 AM, <oleg@okmij.org> wrote:

>
> 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).
>
>

[-- Attachment #2: Type: text/html, Size: 2775 bytes --]

  reply	other threads:[~2014-09-30  9:08 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         ` [Caml-list] Why List.map does not be implemented oleg
2014-09-30  9:07           ` Gabriel Scherer [this message]
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=CAPFanBFyQApQX7rwkjy1PCyKqyyjuP0YauOJcnw58AFoEiyGZg@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    --cc=oleg@okmij.org \
    /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).