From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id E688C7FACD for ; Tue, 30 Sep 2014 10:47:11 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of oleg@okmij.org) identity=pra; client-ip=66.39.3.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="oleg@okmij.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of oleg@okmij.org designates 66.39.3.115 as permitted sender) identity=mailfrom; client-ip=66.39.3.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="oleg@okmij.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@www1.g3.pair.com) identity=helo; client-ip=66.39.3.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="postmaster@www1.g3.pair.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtQCANttKlRCJwNzaWdsb2JhbABghmrPPgKBERYBEQ0HDQdChAQCBHkbIRMBIB0rFIhDvxwYjzZoBxaDGIEdBZ0nAZlcIYJ5AQEB X-IPAS-Result: AtQCANttKlRCJwNzaWdsb2JhbABghmrPPgKBERYBEQ0HDQdChAQCBHkbIRMBIB0rFIhDvxwYjzZoBxaDGIEdBZ0nAZlcIYJ5AQEB X-IronPort-AV: E=Sophos;i="5.04,625,1406584800"; d="scan'208";a="98569994" Received: from www1.g3.pair.com ([66.39.3.115]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 30 Sep 2014 10:46:43 +0200 Received: by www1.g3.pair.com (Postfix, from userid 9370) id 1FFBAC3825; Tue, 30 Sep 2014 04:46:41 -0400 (EDT) From: oleg@okmij.org To: gabriel.scherer@gmail.com CC: goswin-v-b@web.de, caml-list@inria.fr In-reply-to: Message-Id: <20140930084641.1FFBAC3825@www1.g3.pair.com> Date: Tue, 30 Sep 2014 04:46:41 -0400 (EDT) Subject: Re: [Caml-list] Why List.map does not be implemented 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).