caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Transforming side-effects to a monad
@ 2017-03-23 19:56 Christoph Höger
  2017-03-23 20:59 ` Jeremy Yallop
  2017-05-09 13:40 ` Oleg
  0 siblings, 2 replies; 4+ messages in thread
From: Christoph Höger @ 2017-03-23 19:56 UTC (permalink / raw)
  To: caml users


[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-09 17:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-23 19:56 [Caml-list] Transforming side-effects to a monad Christoph Höger
2017-03-23 20:59 ` Jeremy Yallop
2017-05-09 13:40 ` Oleg
2017-05-09 17:15   ` Yaron Minsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).