{"title":"Asymptotic speedup via effect handlers","authors":"DANIEL HILLERSTRÖM, SAM LINDLEY, JOHN LONGLEY","doi":"10.1017/s0956796824000030","DOIUrl":null,"url":null,"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 <jats:italic>generic count</jats:italic> problem in the context of a pure functional base language <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline1.png\" /> <jats:tex-math> ${\\lambda_{\\textrm{b}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> and an extension <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline2.png\" /> <jats:tex-math> ${\\lambda_{\\textrm{h}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> with general <jats:italic>effect handlers</jats:italic>. We prove that <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline3.png\" /> <jats:tex-math> ${\\lambda_{\\textrm{h}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> admits an asymptotically more efficient implementation of generic count than any implementation in <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline4.png\" /> <jats:tex-math> ${\\lambda_{\\textrm{b}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>. We also show that this gap remains even when <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline5.png\" /> <jats:tex-math> ${\\lambda_{\\textrm{b}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> is extended to a language <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline6.png\" /> <jats:tex-math> ${{{{{{\\lambda_{\\textrm{a}}}}}}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> with <jats:italic>affine effect handlers</jats:italic>, 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.","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"202 1","pages":""},"PeriodicalIF":1.1000,"publicationDate":"2024-04-05","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Journal of Functional Programming","FirstCategoryId":"94","ListUrlMain":"https://doi.org/10.1017/s0956796824000030","RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q4","JCRName":"COMPUTER SCIENCE, SOFTWARE ENGINEERING","Score":null,"Total":0}
引用次数: 0
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.
期刊介绍:
Journal of Functional Programming is the only journal devoted solely to the design, implementation, and application of functional programming languages, spanning the range from mathematical theory to industrial practice. Topics covered include functional languages and extensions, implementation techniques, reasoning and proof, program transformation and synthesis, type systems, type theory, language-based security, memory management, parallelism and applications. The journal is of interest to computer scientists, software engineers, programming language researchers and mathematicians interested in the logical foundations of programming.