ocaml-multicore / effects-examples

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

Substitute first-class modules with records. #30

Closed DeVilhena-Paulo closed 1 year ago

DeVilhena-Paulo commented 1 year ago

Instead of using a first-class module containing the effect declarations Get and Set, one can use functions that perform these effects. One can then pack these functions in a record with which a Ref client is resumed.

kayceesrk commented 1 year ago

Looks good to me! Thanks @DeVilhena-Paulo. I'll merge once the CI is green.

dhil commented 1 year ago

Maybe we can have both examples? One using module another using records?

kayceesrk commented 1 year ago

@dhil in both of the proposed examples, the use of effects is similar, isn’t it? In my mind, the aim of the repo is to collect the uses of effects for implementing useful features. If there are two implementations of the same “feature” that only differ by the non effect handler part of the code, my feeling is to only retain the simpler version of the two. What do you think?

dhil commented 1 year ago

It is fine by me.

DeVilhena-Paulo commented 1 year ago

@kayceesrk @dhil Many thanks for reviewing this PR! I agree with @kayceesrk: both examples implement ML-like refs by dynamically installing new handlers for freshly generated effects. The implementation with records is slightly simpler, and it also shows that there is no need for first-class effect names. The implementation could be ported to any language with support for allocation of fresh effect names and first-class functions.

kayceesrk commented 1 year ago

Thanks. CI seems to be having some issues. I’ll merge this PR given that we’ve reviewed it.