Hostname: page-component-6766d58669-rxg44 Total loading time: 0 Render date: 2026-05-15T19:31:16.949Z Has data issue: false hasContentIssue false

Asymptotic speedup via effect handlers

Part of: ICFP20/21

Published online by Cambridge University Press:  05 April 2024

DANIEL HILLERSTRÖM
Affiliation:
Laboratory for Foundations of Computer Science, The University of Edinburgh, Edinburgh EH8 9YL, UK (e-mail: daniel.hillerstrom@ed.ac.uk)
SAM LINDLEY
Affiliation:
Laboratory for Foundations of Computer Science, The University of Edinburgh, Edinburgh EH8 9YL, UK (e-mail: sam.lindley@ed.ac.uk)
JOHN LONGLEY
Affiliation:
Laboratory for Foundations of Computer Science, The University of Edinburgh, Edinburgh EH8 9YL, UK (e-mail: jrl@staffmail.ed.ac.uk)
Rights & Permissions [Opens in a new window]

Abstract

We study a fundamental efficiency benefit afforded by delimited control, showing that for certain higher-order functions, a language with advanced control features offers an asymptotic improvement in runtime over a language without them. Specifically, we consider the generic count problem in the context of a pure functional base language ${\lambda_{\textrm{b}}}$ and an extension ${\lambda_{\textrm{h}}}$ with general effect handlers. We prove that ${\lambda_{\textrm{h}}}$ admits an asymptotically more efficient implementation of generic count than any implementation in ${\lambda_{\textrm{b}}}$. We also show that this gap remains even when ${\lambda_{\textrm{b}}}$ is extended to a language ${{{{{{\lambda_{\textrm{a}}}}}}}}$ with affine effect handlers, which is strong enough to encode exceptions, local state, coroutines and single-shot continuations. This locates the efficiency difference in the gap between ‘single-shot’ and ‘multi-shot’ versions of delimited control.

To our knowledge, these results are the first of their kind for control operators.

Information

Type
Research Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2024. Published by Cambridge University Press
Figure 0

Fig. 1. Typing rules for ${\lambda_{\textrm{b}}}$.

Figure 1

Fig. 2. Contextual small-step operational semantics.

Figure 2

Fig. 3. Additional typing rules for ${\lambda_{\textrm{h}}}$.

Figure 3

Fig. 4. Abstract machine semantics for ${\lambda_{\textrm{b}}}$.

Figure 4

Fig. 5. Abstract machine semantics for ${\lambda_{\textrm{h}}}$.

Figure 5

Fig. 6. Examples of decision trees.

Figure 6

Fig. 7. An implementation of ${\mathrm{bestshot}}$ in ${\lambda_{\textrm{b}}}$ with memoisation.

Figure 7

Fig. 8. An implementation of Berger count in ${\lambda_{\textrm{b}}}$.

Figure 8

Fig. 9. Typing Rules for ${{{{{{\lambda_{\textrm{a}}}}}}}}$

Figure 9

Table 1. Runtime of the n-Queens procedures relative to the effectful implementation

Figure 10

Table 2. Runtime of exact real integration procedures relative to the effectful implementation

Figure 11

Fig. A1. Mapping from base machine configurations to terms.

Figure 12

Fig. B1. Mapping from handler machine configurations to terms.

Submit a response

Discussions

No Discussions have been published for this article.