Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate the possibility of adding algebraic effect handlers with a monad encoding #176

Open
robotlolita opened this issue Feb 1, 2018 · 5 comments

Comments

@robotlolita
Copy link
Member

robotlolita commented Feb 1, 2018

Forster, Kammar, Lindley and Pretnar compare the expressiveness of effects with different formulations in https://arxiv.org/abs/1610.09161, by defining rules for translating between each other. They note that translations from effect handlers into monads do not preserve well typedness in their type system.

If you're not familiar with algebraic effect handlers you should read Pretnar's tutorial: http://www.eff-lang.org/handlers-tutorial.pdf

Algebraic effects and handlers are very interesting to add to JS:

  • Unlike monads, they compose (so you don't need monad transformers and other hacks);
  • They have neat algebraic properties, as effects + operations form a specific algebra. Reasoning about effects is much simpler here, in particular when they compose;
  • Users can provide their own handlers, which is particularly great for e.g.: testing, but can also be used for adding modes to an application (e.g.: a trace mode where effects are recorded and a replay mode where the effects are replayed from a file). Without changing any code;
  • They generalise Task the-right-way(tm);
  • THEY ALLOW DIRECT STYLE (see https://arxiv.org/abs/1611.09259, it's super neat);

Possible problems:

  • TypeScript doesn't have a very expressive type system, BUT we have some type-level operations and we can generate types, so it might be possible to try an approach like Scala's DOT to stack the effects;
  • Handlers require dynamic scoping, this should be possible to replicate with monadic bind (see Reader), but idk;
  • Would we want to rewrite Task in terms of Effect? And what would be the implications of that?
@cyberglot
Copy link

pretty sure Niki's and Daan's paper on Koka talks about that.

@Avaq
Copy link

Avaq commented Sep 20, 2018

https://github.com/briancavalier/forgefx might be relevant.

@robotlolita
Copy link
Member Author

@cyberglot mmh, is it published yet, and do you have a link/name for that paper? The ones linked in the Koka page don't have any coauthor or seem to involve monads from the abstract.

@robotlolita
Copy link
Member Author

Oh, nevermind, I found it going to Niki's page (assuming it's this one http://goto.ucsd.edu/~nvazou/koka/padl16.pdf)

@cyberglot
Copy link

@robotlolita yep, that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants