HackerPapers

arXiv:2104.00250cs.PL

Retrofitting Effect Handlers onto OCaml

KC Sivaramakrishnan, Stephen Dolan, Leo White, Tom Kelly, Sadiq Jaffer, Anil Madhavapeddy

Abstract

Effect handlers have been gathering momentum as a mechanism for modular programming with user-defined effects. Effect handlers allow for non-local control flow mechanisms such as generators, async/await, lightweight threads and coroutines to be composably expressed. We present a design and evaluate a full-fledged efficient implementation of effect handlers for OCaml, an industrial-strength multi-paradigm programming language. Our implementation strives to maintain the backwards compatibility and performance profile of existing OCaml code. Retrofitting effect handlers onto OCaml is challenging since OCaml does not currently have any non-local control flow mechanisms other than exceptions. Our implementation of effect handlers for OCaml: (i) imposes a mean 1% overhead on a comprehensive macro benchmark suite that does not use effect handlers; (ii) remains compatible with program analysis tools that inspect the stack; and (iii) is efficient for new code that makes use of effect handlers.

arXiv comments
Accepted to PLDI 2021
Journal reference
DOI
doi:10.1145/3453483.3454039
Subjects
cs.PLProgramming Languages

On Hacker News

Linked by 4 identifiable commenters in 7 comments across 5 threads, from May 2021 to Mar 2023. Found in 2 HN submissions from Dec 2021 to May 2022. Open submission discussions.

Comments linking this paper, per year.

Discussed in comments5 threads

    • > Do you have any good resources on OCaml5 effect handlers I can follow? I encourage you to have a look at the published paper, it's an easy read and covers the motivation and examples: https://arxiv.org/abs/2104.00250 Here's an excellent talk that walks through modifying a…

      grumpyproleView on HNParent context

  1. OCaml 5.0 Multicore is out 1 comment
    • We certainly hope so. You may find Thomas Leonard's talk from last year's workshop interesting: https://watch.ocaml.org/videos/watch/74ece0a8-380f-4e2a-bef5... The paper we wrote on retrofitting effect handlers: https://arxiv.org/abs/2104.00250 also has some http benchmarks

      sadiqView on HNParent context

    • Non-contiguous stacks are typically just linked-lists of call frames, or groups or call frames. One of the examples that used to be regularly trotted out comp.lang.c 15+ years ago was an IBM mainframe environments, where stacks were linked lists but still managed by hardware.…

      wahernView on HNParent context

    • It involved a fair amount of research and there were many technical challenges. Maintaining backwards compatibility in terms of language features and single-threaded performance puts constraints around what you can implement. Also from my personal experience, debugging segfaults…

      sadiqView on HNParent context

  2. Multicore OCaml: April 2021 3 comments
    • Not dumb questions at all. Multicore adds parallelism via Domains (which are essentially heavyweight threads) and concurrency via Effects and fibers. There's a multicore GC that supports both of those. We plan to upstream things in two parts. First domains-only parallelism and…

      sadiqView on HNParent context

    • Good questions! 1) As I mentioned in https://news.ycombinator.com/item?id=27142502 there is support for parallelism and concurrency. Giving an example of where these might be useful in a webservice. The addition of shared-memory parallelism is beneficial where you might have a…

      sadiqView on HNParent context

    • Abandoned is perhaps too strong a term :-). Effect handlers in the language are supported by fibers, lightweight stacklets managed by the runtime. The details of the implementation can be found in the upcoming research paper in PLDI'21 conference [1]. The effect handlers in…

      kcsrkView on HNParent context

Submitted to Hacker News

Connected through shared HN threads, not inferred similarity or a recommendation.