From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr 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 6F1DC7EC6E for ; Mon, 27 Jan 2014 10:32:07 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.15.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=mailfrom; client-ip=212.227.15.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.15.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AskCALAm5lLU4w8EnGdsb2JhbABZux6FT4EKFg4BAQEBAQYNCQkUKIIlAQEBBCcTTwsYCSUPBSiIJAEYwXsfhg4XjxQWgw6BFASYJoYxEo8K X-IPAS-Result: AskCALAm5lLU4w8EnGdsb2JhbABZux6FT4EKFg4BAQEBAQYNCQkUKIIlAQEBBCcTTwsYCSUPBSiIJAEYwXsfhg4XjxQWgw6BFASYJoYxEo8K X-IronPort-AV: E=Sophos;i="4.95,728,1384297200"; d="scan'208";a="54973069" Received: from mout.web.de ([212.227.15.4]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 27 Jan 2014 10:32:07 +0100 Received: from frosties.localnet ([37.49.32.119]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0M5fxo-1VNkhJ3Lq4-00xc7O for ; Mon, 27 Jan 2014 10:32:05 +0100 Received: from mrvn by frosties.localnet with local (Exim 4.80) (envelope-from ) id 1W7iY1-0006Xy-5k for caml-list@inria.fr; Mon, 27 Jan 2014 10:32:05 +0100 Date: Mon, 27 Jan 2014 10:32:05 +0100 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20140127093204.GA24902@frosties> References: <20140121094939.GA13578@frosties> <20140123092009.GA20624@frosties> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Provags-ID: V03:K0:XrgQ/6YPVWdmYsCVzeQhH2DNjrYdHhnNWEf7vJoaACZRFSbq0oL GqaySDO6wxYUBt6eXYHwXydlavRhzNMcHvsiDdcLWZ/ihieA2r1cgCyO0BnfoEartCllUsG G8PpUl0fkl0rvY9Lfp4lVhOiHdlYQEvt2dgVyRn0cQTWZErsZmREXkMZ1c7UuWFClCRItLl y2fVttnq6X+PGmwk051/g== Subject: Re: [Caml-list] Purity in ocaml On Thu, Jan 23, 2014 at 10:35:14AM +0100, Arnaud Spiwack wrote: > > On the other hand if types are annotated with the exceptions they > > throw then they become just another return value and become pure. > > Same input, same exception every time. > > > > As far as Yotam Barnoy's goal is concerned, this isn't true. He wants to be > able to use purity annotations for optimisation: a most typical > optimisation which is valid only for pure functions is to rewrite *map f > (map g l)* into *map (f???g) l*. This optimisation, as it happens, is not > valid with exception throwing functions as it may very well throw a > different exception. Do you mean something like this? let g = function 0 -> raise G | n -> n let f = function 1 -> raise F | n -> n map f (map g [1;0]) ===> raise G map (f %> g) [1;0] ===> raise F It is true, the exception prevents any optimization that would reorder two functions that both throw an excepition. But many other optimizations are still possible, e.g. common subexpression elimination: let n = let x = f (g 1) in let y = g 1 in x + y ==> let n = let t = g 1 in let x = f t in let y = t in x + y MfG Goswin