From: "Christoph Höger" <choeger@umpa-net.de>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] Transforming side-effects to a monad
Date: Thu, 23 Mar 2017 20:56:16 +0100 [thread overview]
Message-ID: <5af3b33f-d4eb-05dc-d774-b42f63275776@umpa-net.de> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 974 bytes --]
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 = ref 0
let incr x = counter := !counter + x ; !counter
let put n = counter := n; !counter
put (5 + let f x = 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 = 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
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next reply other threads:[~2017-03-23 19:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-23 19:56 Christoph Höger [this message]
2017-03-23 20:59 ` Jeremy Yallop
2017-05-09 13:40 ` Oleg
2017-05-09 17:15 ` Yaron Minsky
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=5af3b33f-d4eb-05dc-d774-b42f63275776@umpa-net.de \
--to=choeger@umpa-net.de \
--cc=caml-list@inria.fr \
/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