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 4A8F37F0AB for ; Thu, 23 Mar 2017 20:56:19 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=choeger@umpa-net.de; spf=None smtp.mailfrom=choeger@umpa-net.de; spf=None smtp.helo=postmaster@mail.umpa-net.de Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of choeger@umpa-net.de) identity=pra; client-ip=85.25.45.218; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="choeger@umpa-net.de"; x-sender="choeger@umpa-net.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of choeger@umpa-net.de) identity=mailfrom; client-ip=85.25.45.218; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="choeger@umpa-net.de"; x-sender="choeger@umpa-net.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail.umpa-net.de) identity=helo; client-ip=85.25.45.218; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="choeger@umpa-net.de"; x-sender="postmaster@mail.umpa-net.de"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3ACMIY5xw1T5gbmVjXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?1OsfIJqq85mqBkHD//Il1AaPBtSHraocw8Pt8InYEVQa5piAtH1QOLdtbDQizf?= =?us-ascii?q?ssogo7HcSeAlf6JvO5JwYzHcBFSUM3tyrjaRsdF8nxfUDdrWOv5jAOBBr/KRB1?= =?us-ascii?q?JuPoEYLOksi7ze6/9pncbglSmDaxfa55IQmrownWqsQYm5ZpJLwryhvOrHtIeu?= =?us-ascii?q?BWyn1tKFmOgRvy5dq+8YB6/ShItP0v68BPUaPhf6QlVrNYFygpM3o05MLwqxbO?= =?us-ascii?q?SxaE62YGXWUXlhpIBBXF7A3/U5zsvCb2qvZx1S+HNsDwULs6Wymt771zRRH2iC?= =?us-ascii?q?kJKj03/m/ZhcN/kK1Wux2hqwBlzoDTfI2YOvhzc6XAdt0aX2pBWcNRWjRfD4O8?= =?us-ascii?q?dYsPDvEBPfpfr4nlp1sBtRmwHQ+jBOzx0D9Dm3j70rE60+QmDw7G0xIvH8gVvX?= =?us-ascii?q?TJqdX1LL0dXfmzzKbW0TXPde5Z1ink5YXObxsvoumMUKpzfMfR00UjCQPIgk+f?= =?us-ascii?q?pIHlJT+ZyPkBvmuD4+dkSO6jkW8qpgBrrjSx2MsgkJTFi4ARx13C6C532pw6Jc?= =?us-ascii?q?eiR05+edOkEIVftyWdN4ZuR8MtWWBouCIgxr0bvJ67ZDIFxI0hxxHBd/yLaZWH?= =?us-ascii?q?7Qz7WOaQJzd3mm5ldaq8ihuy60Ss1O3xWtO73VtKtCZJjMTAu3MV2xzW8MeHS/?= =?us-ascii?q?99/km72TaI0gDe8v1LIUAzlaXFJJ4u3KQwm4EOsUTGBi/5glz6jKmIeUU44OSn?= =?us-ascii?q?9vrobq38ppCAL490lh3+MqM2l8OjG+s4NwwOU3Gf+eS9z73j4Vb0QK5Kj/0ziq?= =?us-ascii?q?nWqorWJcUdpq6jAg9ayJwv6xilD2Tu7NNNlnACKBpYYx+dlMC9MFjLJLX8DOyj?= =?us-ascii?q?q1WqijZigf7caO7PGJLIe1PDirb6YbFl63l8VgU+15gL7JJTB74MOtruX1f48d?= =?us-ascii?q?rVElk1PlrnkK7cFNxh29ZGCiq0CaiDPfaKvA=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0A8NgA3J9RYZNotGVVeHAEFAQsBGAEBB?= =?us-ascii?q?AEBCgEBgyZkhGqzNYk8RBMBAQEBAQEBAQEBAQNcM4IzIIJsgTMCXw0IAQGKBpo?= =?us-ascii?q?1kAaCJopnD4hTigoMLoJfBZxVg3qCDIQeknoFhlaTYjcfgQVaFEGECAwBgkSKf?= =?us-ascii?q?QEBAQ?= X-IPAS-Result: =?us-ascii?q?A0A8NgA3J9RYZNotGVVeHAEFAQsBGAEBBAEBCgEBgyZkhGq?= =?us-ascii?q?zNYk8RBMBAQEBAQEBAQEBAQNcM4IzIIJsgTMCXw0IAQGKBpo1kAaCJopnD4hTi?= =?us-ascii?q?goMLoJfBZxVg3qCDIQeknoFhlaTYjcfgQVaFEGECAwBgkSKfQEBAQ?= X-IronPort-AV: E=Sophos;i="5.36,211,1486422000"; d="asc'?scan'208";a="265944150" Received: from mail.umpa-net.de ([85.25.45.218]) by mail2-smtp-roc.national.inria.fr with ESMTP; 23 Mar 2017 20:56:18 +0100 Received: from [192.168.178.42] (ip5b4216b3.dynamic.kabel-deutschland.de [91.66.22.179]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: choeger) by mail.umpa-net.de (Postfix) with ESMTPSA id B9C447A20A96 for ; Thu, 23 Mar 2017 19:56:17 +0000 (UTC) To: caml users From: =?UTF-8?Q?Christoph_H=c3=b6ger?= Message-ID: <5af3b33f-d4eb-05dc-d774-b42f63275776@umpa-net.de> Date: Thu, 23 Mar 2017 20:56:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="9aiT9ejtv0OJsW5brD20TJ0CBL9w3wm2F" X-Validation-by: choeger@umpa-net.de Subject: [Caml-list] Transforming side-effects to a monad This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --9aiT9ejtv0OJsW5brD20TJ0CBL9w3wm2F Content-Type: multipart/mixed; boundary="ecXsHutHiDBXvxmtLo4tPNDtPhr1E4dBq"; protected-headers="v1" From: =?UTF-8?Q?Christoph_H=c3=b6ger?= To: caml users Message-ID: <5af3b33f-d4eb-05dc-d774-b42f63275776@umpa-net.de> Subject: Transforming side-effects to a monad --ecXsHutHiDBXvxmtLo4tPNDtPhr1E4dBq Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Dear all, this is not entirely OCaml related, but somewhat more general. However, I hope that someone on that list can give me a pointer on how to proceed. Assume a simple OCaml program with two primitives that can cause side-effects: let counter =3D ref 0 let incr x =3D counter :=3D !counter + x ; !counter let put n =3D counter :=3D n; !counter put (5 + let f x =3D incr x in f 3) This example can be transformed into a pure program using a counter monad (using ppx_monadic syntax): do_; i <-- let f x =3D incr x in f 3 ; p <-- put (5 + i) return p For a suitable definition of bind and return, both programs behave equivalently. My question is: How can one automatically translate a program of the former kind to the latter? I assume, one needs a normal form that makes the order of evaluation explicit, but which normal form would that be? Is there a textbook algorithm for that kind of analysis? any pointers are appreciated, Christoph --ecXsHutHiDBXvxmtLo4tPNDtPhr1E4dBq-- --9aiT9ejtv0OJsW5brD20TJ0CBL9w3wm2F Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAljUKGAACgkQhMBO4cVSGS8vvgCdFEW2zgrm3MT/Q51Bnq0QZPC0 2gMAnixpiOjBy57yZK/jVxZ5pOFGaKnk =KkCk -----END PGP SIGNATURE----- --9aiT9ejtv0OJsW5brD20TJ0CBL9w3wm2F--