ocaml-multicore / effects-examples

Examples to illustrate the use of algebraic effects in Multicore OCaml
ISC License
423 stars 35 forks source link

another implementation of the ref example #7

Closed gmevel closed 8 years ago

gmevel commented 8 years ago

hello,

here is another possible implementation of the “ML‐style references” example. do what you want with it.

it is in substance an automated mechanism to nest the single state example. it does not require an universal type (nor a phony failwith), and is in this sense simpler. however, as in Alain Frisch’s implementation of universal type, a reference is a first‐value module with its own constructor (effects here). instead of having an universal list of all the values of all the references, we have nested handlers, one block per reference, plus one for reference creation. the cost of propagating effects through those nested handlers is comparable to the one of finding the value in the list (or would be if the previous implementation took care of removing outdated values from the list).

kayceesrk commented 8 years ago

Excellent. This is much cleaner!