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 9F3ED7EC6E for ; Tue, 28 Jan 2014 10:22:01 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of arnaud.spiwack@gmail.com) identity=pra; client-ip=74.125.82.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="arnaud.spiwack@gmail.com"; x-sender="arnaud.spiwack@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of arnaud.spiwack@gmail.com designates 74.125.82.45 as permitted sender) identity=mailfrom; client-ip=74.125.82.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="arnaud.spiwack@gmail.com"; x-sender="arnaud.spiwack@gmail.com"; 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@mail-wg0-f45.google.com) identity=helo; client-ip=74.125.82.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="arnaud.spiwack@gmail.com"; x-sender="postmaster@mail-wg0-f45.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQDADp251JKfVItlGdsb2JhbABag0RWgn2mG4ppiFSBCwgWDgEBAQEHCwsJEiqCJQEBAQMBIwQZAS0LAQMBCwEFAwIEBxodAgIiEgEFAQoSBiWHXwMJCA2NbY9ojAmDXJMzJwMKiC4RAQUMjm+CeoFJBJgngTKPABgpgWWCdTs X-IPAS-Result: ArQDADp251JKfVItlGdsb2JhbABag0RWgn2mG4ppiFSBCwgWDgEBAQEHCwsJEiqCJQEBAQMBIwQZAS0LAQMBCwEFAwIEBxodAgIiEgEFAQoSBiWHXwMJCA2NbY9ojAmDXJMzJwMKiC4RAQUMjm+CeoFJBJgngTKPABgpgWWCdTs X-IronPort-AV: E=Sophos;i="4.95,735,1384297200"; d="scan'208";a="55188246" Received: from mail-wg0-f45.google.com ([74.125.82.45]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Jan 2014 10:22:01 +0100 Received: by mail-wg0-f45.google.com with SMTP id n12so258431wgh.24 for ; Tue, 28 Jan 2014 01:22:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=WzZZuNeGrA49droiKDh/6wRt77IkEI9tf6MB83M+0RA=; b=E+xqeXESLYlKp6XYfPkH53kcHCS2r+BXetHZ34szn9HiTCMAPgqIOMUDRB4yckKQ9Y uMaG6pbA6si0jLu6GyJyWfpx2RYUCzMVS2OmRER0lql+6IK1tDXloEz9ZOUICvD2ljnF tx09ShXwL4XeWmuPPTCqBJG+ZyRJWQpjEC84HA7s5pKWH1YEun/hKfKRt6OD84MiPGkj FWbH/PK19ZrPzEpmrw3wtIBzf7PQSvctTP+kZQL2r58LhVnNuVIdUWmu847qrWk2/K8L j2HWtAlBF6FewWs5VOhtyqG+vomn1JjNzJyvTkPmnlz5pPRMRqhsRKhW3fgGw0AYsUQJ B4Ww== X-Received: by 10.194.185.237 with SMTP id ff13mr358310wjc.64.1390900920772; Tue, 28 Jan 2014 01:22:00 -0800 (PST) MIME-Version: 1.0 Sender: arnaud.spiwack@gmail.com Received: by 10.227.43.2 with HTTP; Tue, 28 Jan 2014 01:21:20 -0800 (PST) In-Reply-To: <20140127093204.GA24902@frosties> References: <20140121094939.GA13578@frosties> <20140123092009.GA20624@frosties> <20140127093204.GA24902@frosties> From: Arnaud Spiwack Date: Tue, 28 Jan 2014 10:21:20 +0100 X-Google-Sender-Auth: rRsfy-2ro3Xo0EgBi9cgYbN3fwI Message-ID: To: Goswin von Brederlow Cc: OCaML Mailing List Content-Type: multipart/alternative; boundary=047d7bb03ea04ceeb204f1045ba9 X-Validation-by: arnaud@spiwack.net Subject: Re: [Caml-list] Purity in ocaml --047d7bb03ea04ceeb204f1045ba9 Content-Type: text/plain; charset=UTF-8 > 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. Precisely > 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 > To some degree: let n = let x = f (g 1) (h ()) in let y = g 1 in x+y is a different program than let n = let t = g 1 in let x = f t (h ()) in let y = t in x+y As it reorders (g 1) and (h ()). I think the rule is something like: when the program is in monadic form, and you have a call to e, you can factor in every subsequent calls to e. Which I guess is good enough. But I would tend to believe deforestation would be tremendously more useful than common expression elimination. > > MfG > Goswin > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --047d7bb03ea04ceeb204f1045ba9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

=
Do you mean something like this?

let g =3D function 0 -> raise G | n -> n
let f =3D function 1 -> raise F | n -> n

map f (map g [1;0]) =3D=3D=3D> raise G
map (f %> g) [1;0] =C2=A0=3D=3D=3D> raise F

It is true, the exception prevents any optimization that would reorder
two functions that both throw an excepition.

Precisely=
=C2=A0
But many other
optimizations are still possible, e.g. common subexpression
elimination:

let n =3D
=C2=A0 let x =3D f (g 1) in
=C2=A0 let y =3D g 1 in
=C2=A0 x + y

=3D=3D>

let n =3D
=C2=A0 let t =3D g 1 in
=C2=A0 let x =3D f t in
=C2=A0 let y =3D t in
=C2=A0 x + y

To some degree:

let n =3D
=C2=A0 let x =3D f (g 1) (h ()) in
=C2=A0= let y =3D g 1 in
=C2=A0 x+y

is a different program than
let n =3D
=C2=A0 let t =3D g 1 in
=C2=A0 let x =3D f t (h ()) in
= =C2=A0 let y =3D t in
=C2=A0 x+y

As it reorders (g 1) and (= h ()). I think the rule is something like: when the program is in monadic f= orm, and you have a call to e, you can factor in every subsequent calls to = e. Which I guess is good enough. But I would tend to believe deforestation = would be tremendously more useful than common expression elimination.
=C2=A0

MfG
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Goswin

--
Caml-list mailing list. =C2=A0Subscription management and archives:
ht= tps://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--047d7bb03ea04ceeb204f1045ba9--