Skip to content

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

Open
@robotlolita

Description

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?

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions