EHOP: Effect Handler Oriented Programming

Lead Research Organisation: University of Edinburgh
Department Name: Sch of Informatics

Abstract

In an economy in which the UK software industry added £139 billion of
value to UK GDP in 2018 alone, this fellowship will transform the way
developers write software. By offering a radically new way of
composing and customising programs, I will empower software developers
to build more flexible, maintainable, and robust software.

Computers must interact with the real world. In computer programs real
world effects are pervasive, e.g.: concurrency (performing two
computations at once), distribution (performing computation in
different places), input, output, and probability (e.g. for machine
learning).

Effect handlers are a general programming feature that can be used to
implement all of these effects. They were introduced by theoretical
computer scientists as part of a mathematical model of effects. Thanks
in part to my efforts they now show promise as a practical programming
tool. Interest in effect handlers in industry is growing. For
instance, Meta's React Fiber, the core of the market-leading React
user interface library for web applications, is directly inspired by
effect handlers, and Uber's Pyro tool for probabilistic programming
and statistical inference makes essential use of effect handlers.

Preliminary results suggest effect handlers have the potential to
support efficient implementations. Nevertheless, existing
implementations are in their infancy and research is required to make
them scale, both in terms of ease of programming and in terms of
performance. I will develop the theory and practice of Effect Handler
Oriented Programming as a uniform foundation for modular and efficient
implementation of effects. I will create both high-level (for humans)
and low-level (for machines) effect handler designs and
implementations. In collaboration with my project partners I will
ensure that EHOP has direct impact through two key technologies.

+ OCaml. OCaml 5 (released 2022) is the first industrial-strength
language with efficient native support for effect handlers, and this
support is already bearing fruit, e.g, the Eio 1.0 library (2024)
depends on effect handlers to offer seamless high-performance
fine-grained control over a range of concurrency and asynchronous I/O
features. I will develop an ergonomic effect type system for OCaml,
enabling more flexible, maintainable, and robust software to be
written in OCaml. Eventually these benefits will transfer to other
languages, ultimately improving the user experience for billions of
end users.

+ WebAssembly. I am designing and implementing an effect handler
extension for WebAssembly, a portable low-level bytecode supported by
the top four browser vendors and designed to supersede JavaScript as
the target language for the web. Currently, languages such as
JavaScript provide a collection of ad hoc overlapping concurrency
features, each of which is hard-wired and must be maintained
separately. However, all of them can be implemented with minimal
effort using effect handlers. Rather than hard-wiring and maintaining
several ad hoc features, compiler developers will be able to rely on a
single implementation of effect handlers in WebAssembly. This will
enable more flexible, maintainable, and reliable programming language
implementations, ultimately improving the user experience of billions
of web users.

A "killer app" for effect handlers is concurrency and distribution,
central to which is communication. For communication to be safe,
secure, and reliable, all parties must comply with appropriate
protocols. Session types are a nascent technology for enforcing
protocol compliance. Unifying the two main threads of my research over
the last decade, I will extend the theory and practice of effect
handlers to enable session-typed concurrency and distribution features
to be defined as effect handlers. Ultimately, this will enable safe,
secure, and reliable communication infrastructure for billions of end
users.

Publications

10 25 50