Informatics researchers awarded for their seminal work on effect handlers

[24/05/2022] Gordon Plotkin and Matija Pretnar (a former PhD in the Laboratory for the Foundations of Computer Science at the School of Informatics) were recognised for their ground-breaking 2009 paper Handlers of Algebraic Effects which received the Test of Time Award at the ETAPS conference on 6th April.

Image
Geometric shapes and formulas, abstract background

Effect handlers provide a computation construct that makes it easier to write more expressive and flexible computer programs. Its numerous applications include the Web’s most popular user-interface framework called React that runs daily for billions of users on multiple platforms such as Instagram, WhatsApp or BBC News.

The Effect Handler

Each programming language breaks down into several grammatical constructs. The effect handler that School of Informatics researchers invented provide two such constructs that work together. The first construct, the effect operation, lets programmers tell the program 'something special should happen here' without explaining what exactly should happen. The second construct, the effect handler, lets programmers delimit a part of the program and say 'these are the special things that should happen for these effect operations'. 

The simplest example of an effect operation is the exception. Programmers use and handle exceptions when the program encounters an exceptional situation, for example, an input value was meant to be at least 8 characters long, or the result of a computation we want to divide by is 0. 

Plotkin and Pretnar realised that a programming language can handle effect operations other than exceptions. The main difference is that the handling code can resume execution after doing something special. For example, when a user hits 'submit' on a log-in registration form, instead of invoking an exception when the program encounters an insecure password, an appropriate handler can use a password generator to propose a more secure password to the user instead, and, if the user accepts, continue processing the form as if no exception has happened. 

Effect handlers in action

One exciting application of the effect handler construct is when putting together many small components to create user interfaces such as social media (for example, Instagram) feeds. Such interfaces contain multiple components organised in complicated hierarchies, but their rendering must remain reactive. 

Instagram’s feed contains photos, buttons, notifications, and, as the mouse hovers around the screen, hover-texts and user-tags pop up, and all of these might update as another user tags themselves in a photo, or posts a new message. If the interface is not reactive, users might not enjoy interacting with the feed and migrate to a different platform. 

Effect handlers not only enable a useful design for such complex component hierarchies, they can also save developers’ time. Developers use effect operations whenever their components need to be updated when an external event takes place. Then, an encompassing effect handler works out which components need to update when a new photo is posted, or other information arrives. In this way, the same effect operation may be resumed several times, supplying the user with the latest information, but only the components that need updating are changed, giving the user a smooth, reactive, experience. 

Real life application

This particular application has been adopted by a major open-source web-programming framework React, mainly developed in Meta (formerly Facebook). Their implementation of the effect handler, which they call 'React Hooks' is used on massive scale, and includes many web applications. 

Effect handlers remain an active research topic of the School of Informatics. Sam Lindley's UKRI Future-Leaders Fellowship on Effect Handler Oriented Programming is a major research project in the field. There are also several UG4, MInf, MSc and PhD students graduated after or currently working on the topic. 

The work on effect handlers shows that working on well-chosen basic problems can lead to widespread practical application. But there we were lucky, with quick influential follow-up research on handlers in practice, by our colleagues in Edinburgh and the development of the Eff language at Ljubljana by Andrej Bauer and Matija.

Professor Gordon Plotkin
School of Informatics

The fact that the adoption of our discovery took only ten years is a testament to the whole Programming Languages research community. Its efforts have over and over again shown the practical usefulness of the theoretical research.

Dr Matija Pretnar
University of Ljubljana

An impact case study on effect handlers was included in the School of Informatics and EPCC’s 2021 REF submission, which received 100% top grades for impact. 

Many thanks to Ohad Kammar for his work on developing this story, and Gordon Plotkin for editing it. 

Related links 

Link to the full paper

ETAPS announcement

Informatics 2021 REF results

Examples of Informatics impact case studies