Daan Leijen's research while affiliated with Microsoft and other places

Publications (68)

Article
This paper studies compilation techniques for algebraic effect handlers. In particular, we present a sequence of refinements of algebraic effects, going via multi-prompt delimited control, _generalized evidence passing_, yield bubbling, and finally a monadic translation into plain lambda calculus which can be compiled efficiently to many target pla...
Article
Algebraic effect handlers are a powerful way to incorporate effects in a programming language. Sometimes perhaps even _too_ powerful. In this article we define a restriction of general effect handlers with _scoped resumptions_. We argue one can still express all important effects, while improving reasoning about effect handlers. Using the newly gai...
Chapter
Modern memory allocators have to balance many simultaneous demands, including performance, security, the presence of concurrency, and application-specific demands depending on the context of their use. One increasing use-case for allocators is as back-end implementations of languages, such as Swift and Python, that use reference counting to automat...
Technical Report
We introduce two new language features, called implicit functions and implicit control. Both generalize implicit values (or parameters) which are a typed implementation of dynamic binding. Implicit functions are bound dynamically but evaluated in the lexical scope of their binding. We show how this small generalization from regular implicit values...
Conference Paper
Algebraic effect handlers are a powerful abstraction mechanism that can express many complex control-flow mechanisms. This article extends basic algebraic effect handlers with first class dynamic effects. Dynamic effects add a lot more expressiveness but surprisingly only need minimal changes to the original semantics. As such, dynamic effects are...
Conference Paper
We describe an implementation of algebraic effects and handlers as a library in standard and portable C99, where effect operations can be used just like regular C functions. We use a formal operational semantics to guide the C implementation at every step where an evaluation context corresponds directly to a particular C execution context. Finally...
Conference Paper
JavaScript code running in the Node.js runtime is a major platform for developers building cloud, mobile, or IoT applications. A fundamental concept in Node.js programming is the use of asynchronous callbacks and event loops to provide highly responsive applications. While conceptually simple, this programming model contains numerous subtleties and...
Article
JavaScript code running in the Node.js runtime is a major platform for developers building cloud, mobile, or IoT applications. A fundamental concept in Node.js programming is the use of asynchronous callbacks and event loops to provide highly responsive applications. While conceptually simple, this programming model contains numerous subtleties and...
Conference Paper
Algebraic effect handlers generalize many control-flow abstractions that are implemented specially in most languages, like exception handling, iterators, or backtracking. In this article, we show how we can implement full support for asynchronous programming as a library using just algebraic effect handlers. The consistent type driven approach also...
Article
Algebraic effect handlers, introduced by Plotkin and Power in 2002, are recently gaining in popularity as a purely functional approach to modeling effects. In this article, we give a full overview of practical algebraic effects in the context of a compiled implementation in the Koka language. In particular, we show how algebraic effects generalize...
Conference Paper
Algebraic effect handlers, introduced by Plotkin and Power in 2002, are recently gaining in popularity as a purely functional approach to modeling effects. In this article, we give a full overview of practical algebraic effects in the context of a compiled implementation in the Koka language. In particular, we show how algebraic effects generalize...
Conference Paper
Madoko [6-8] is a novel authoring system for writing complex documents. It is especially well suited for complex academic or industrial documents, like scientific articles, reference manuals, or math-heavy presentations. One particular important aspect of Madoko is to write a document in high-level Markdown [5] with a focus on semantic content. Fro...
Conference Paper
The combination of monads and effects leads to a clean and easy to reason about programming paradigm. Monadic programming is easy to reason about, but can be cumbersome, as it requires explicit lifting and binding. In this paper, we combine monads and effects within a single programming paradigm: we use monads to define the semantics of effect type...
Conference Paper
This paper presents and discusses the internal operation of NCLSC (NCL Stereo Converter): a tool to convert a 2D interactive multimedia application annotated with depth information to a stereoscopic-multimedia application. Stereoscopic-multimedia applications are those that codify both the left-eye and right-eye views, as required by stereoscopic 3...
Article
Full-text available
Monads are a popular tool for the working functional programmer to structure effectful computations. This paper presents polymonads, a generalization of monads. Polymonads give the familiar monadic bind the more general type forall a,b. L a -> (a -> M b) -> N b, to compose computations with three different kinds of effects, rather than just one. Po...
Article
We propose a programming model where effects are treated in a disciplined way, and where the potential side-effects of a function are apparent in its type signature. The type and effect of expressions can also be inferred automatically, and we describe a polymorphic type inference system based on Hindley-Milner style inference. A novel feature is t...
Conference Paper
Software tools researchers can accelerate their ability to learn by exposing tools to users via web technologies, allowing them to observe and test the interactions between humans and tools. At Microsoft Research, we have developed a web service (http://www.rise4fun.com/) for such a purpose that is available for community use.
Conference Paper
Full-text available
Mobile devices commonly access shared data stored on a server. To ensure responsiveness, many applications maintain local replicas of the shared data that remain instantly accessible even if the server is slow or temporarily unavailable. Despite its apparent simplicity and commonality, this scenario can be surprisingly challenging. In particular, a...
Article
Full-text available
Integrating tools and extensions into existing languages, compilers, debuggers, and IDEs can be difficult, work-intensive, and often results in a one-off integration. In this paper, we report on our experience of building and integrating the CodeContract tool set into an existing programming environment. The CodeContract tools enable 1) authoring o...
Conference Paper
Full-text available
When distributed clients query or update shared data, eventual consistency can provide better availability than strong consistency models. However, programming and implementing such systems can be difficult unless we establish a reasonable consistency model, i.e. some minimal guarantees that programmers can understand and systems can provide effect...
Article
Full-text available
When distributed clients query or update shared data, eventual consistency can provide better availability than strong consistency models. However, programming and implementing such systems can be difficult unless we establish a reasonable consistency model, i.e. some minimal guarantees that programmers can understand and systems can provide effect...
Conference Paper
Full-text available
This article presents an extension to the work of Launchbury and Peyton-Jones on the ST monad. Using a novel model for concurrency, called concurrent revisions [3,5], we show how we can use concurrency together with imperative mutable variables, while still being able to safely convert such computations (in the Rev monad) into pure values again. In...
Conference Paper
Parallel or incremental versions of an algorithm can significantly outperform their counterparts, but are often difficult to develop. Programming models that provide appropriate abstractions to decompose data and tasks can simplify parallelization. We show in this work that the same abstractions can enable both parallel and incremental execution. W...
Conference Paper
Parallel or incremental versions of an algorithm can significantly outperform their counterparts, but are often difficult to develop. Programming models that provide appropriate abstractions to decompose data and tasks can simplify parallelization. We show in this work that the same abstractions can enable both parallel and incremental execution. W...
Conference Paper
This article presents an extension to the work of Launchbury and Peyton-Jones on the ST monad. Using a novel model for concurrency, called concurrent revisions [3,5], we show how we can use concurrency together with imperative mutable variables, while still being able to safely convert such computations (in the Rev monad) into pure values again. In...
Conference Paper
Many useful programming constructions can be expressed as monads. Examples include probabilistic modeling, functional reactive programming, parsing, and information flow tracking, not to mention effectful functionality like state and I/O. In this paper, we present a type-based rewriting algorithm to make programming with arbitrary monads as easy as...
Conference Paper
Full-text available
Enabling applications to execute various tasks in parallel is difficult if those tasks exhibit read and write conflicts. We recently developed a programming model based on concurrent revisions that addresses this challenge in a novel way: each forked task gets a conceptual copy of all the shared state, and state changes are integrated only when tas...
Article
Full-text available
Enabling applications to execute various tasks in parallel is difficult if those tasks exhibit read and write conflicts. In recent work, we developed a programming model based on concurrent revisions that addresses this challenge: each forked task gets a conceptual copy of all locations that are declared to be shared. Each such location has a speci...
Conference Paper
Full-text available
Building applications that are responsive and can exploit parallel hardware while remaining simple to write, understand, test, and maintain, poses an important challenge for developers. In particular, it is often desirable to enable various tasks to read or modify shared data concurrently without requiring complicated locking schemes that may throt...
Article
Effects are a powerful and convenient component of program-ming. They enable programmers to interact with the user, take ad-vantage of efficient stateful memory, throw exceptions, and non-deterministically execute programs in parallel. However, they also complicate every aspect of reasoning about a program or language, and as a result it is crucial...
Article
Most programming languages in use today let one freely use arbi-trary (side) effects. This is despite the fact that unknown and un-restricted side effects are the cause of many software problems. We propose a programming model where effects are treated in a disciplined way, and where the potential side-effects of a function are apparent in its type...
Conference Paper
Full-text available
The Task Parallel Library (TPL) is a library for .NET that makes it easy to take advantage of potential parallelism in a program. The library relies heavily on generics and delegate expressions to provide custom control structures expressing structured parallelism such as map-reduce in user programs. The library implementation is built around the n...
Article
We present HML, a type inference system that supports full first-class polymorphism where few annotations are needed: only function parameters with a polymorphic type need to be annotated. HML is a simplification of MLF where only flexibly quantified types are used. This makes the types easier to work with from a programmers perspective, and simpli...
Conference Paper
We present HML, a type inference system that supports full first-class polymorphism where few annotations are needed: only function parameters with a polymorphic type need to be annotated. HML is a simplification of MLF where only flexibly quantified types are used. This makes the types easier to work with from a programmers perspective, and simpli...
Conference Paper
HMF is a conservative extension of Hindley-Milner type inference with first-class polymorphism. In contrast to other proposals, HML uses regular System F types and has a simple type inference algorithm that is just a small extension of the usual Damas-Milner algorithm W. Given the relative simplicity and expressive power, we feel that HMF can be an...
Conference Paper
The MLF type system by Le Botlan and Rémy is a natural extension of Hindley-Milner type inference that supports full first-class polymorphism, where types can be of higher-rank and impredicatively instantiated. Even though MLF is theoretically very attractive, it has not seen widespread adoption. We believe that this partly because it is unclear ho...
Article
datatypes can be typed conveniently using existential types. Even though it is a powerful abstraction mechanism, cur-rent type inference systems based on Hindley-Milner do not allow existential types as first-class citizens – every existential type must be explicitly declared, packed, and unpacked using a data construc-tor. We present an extension...
Conference Paper
MLF is a type system that extends a functional language with impredicative rankpolymorphism. Type inference remains possible and only in some clearly defined situations, a local type annotation is required. Qualified types are a general concept that can accommodate a wide range of type systems extension, for example, type classes in Haskell. We sho...
Conference Paper
Records provide a safe and flexible way to construct data structures. We describe a natural approach to typing polymorphic and exten- sible records that is simple, easy to use in practice, and straightfor- ward to implement. A novel aspect of this work is that records can contain duplicate labels, effectively introducing a form of scoping over the...
Article
wxHaskell is a graphical user interface (GUI) library for Haskell that is built on wxWidgets: a free industrial strength GUI library for C++ that has been ported to all major platforms, including Win- dows, Gtk, and MacOS X. In contrast with many other libraries, wxWidgets retains the native look-and-feel of each particular plat- form. We show how...
Article
Moderne functionele talen zijn mathematisch precies, notationeel elegant, en sterk getypeerd. Deze talen zijn daarom bij uitstek geschikt voor het onderwijzen van programmeerconcepten en algoritmiek. Helium is een onderzoeksproject waarbij een krachtig typesysteem gecombineerd wordt met precieze en gebruiksvriendelijke foutmeldingen
Article
Introduction There exist many denitions of the div and mod functions in computer science literature and programming languages. Boute (Boute, 1992) describes most of these and discusses their mathematical properties in depth. We shall therefore only briey review the most common denitions and the rare, but mathematically elegant, Euclidean division....
Article
Full-text available
Despite the long list of publications on parser combinators, there does not yet exist a monadic parser combinator library that is applicable in real world situations. In particular naive implementations of parser combinators are likely to su#er from space leaks and are often unable to report precise error messages in case of parse errors. The Parse...
Article
this document This document ships in the following formats: Postscript (PS). High quality output, best for printing
Article
Full-text available
Despite the long list of publications on parser combinators, there does not yet exist a monadic parser combinator library that is applicable in real world situations. In particular naive implementations of parser combinators are likely to su#er from space leaks and are often unable to report precise error messages in case of parse errors. The Parse...
Article
Domain-specific embedded languages (DSELs) expressed in higher-order, typed (HOT) languages provide a composable framework for domain-specific abstractions. Such a framework is of greater utility than a collection of stand-alone domain-specific languages. Usually, embedded domain specific languages are build on top of a set of domain specific primi...
Article
Full-text available
The increasing popularity of component-based programming tools offer a big opportunity to designers of advanced programming languages, such as Haskell. If we can package our programs as software components, then it is easy to integrate them into applications written in other languages. In earlier work we described a preliminary integration of Haske...
Conference Paper
Full-text available
Using client-side scripting it is possible to build interactive web pages that don’t need round-trips to the server for every user-event. The web browser exposes itself to the script via an object model (DOM), which means that scripts can add and remove page content, or change the position and color of elements via their style attributes. We explai...
Article
H/Direct is a foreign-language interface for the purely functional language Haskell. Rather than rely on host-language type signatures, H/Direct compiles Interface Definition Language (IDL) to Haskell stub code that marshals data across the interface. This approach allows Haskell to call both C and COM, and allows a Haskell component to be wrapped...
Article
compiles Interface Definition Language (IDL) to Haskell stub code that marshals data across the interface. This approach allows Haskell to call both C and COM, and allows a Haskell component to be wrapped in a C or COM interface. IDL is a complex language and language mappings for IDL are usually described informally. In contrast, we provide a rela...
Article
this article (and many others) are included with HaskellScript and H/Direct is therefore not described any further. The Agent component can be used from Haskell by importing the (automatically generated) AgentScript module
Conference Paper
Full-text available
The expressiveness of higher-order typed languages such as Haskell or ML makes them an attractive medium in which to write software components. Hitherto, however, their use has been limited by the all-or-nothing problem: it is hard to write just part of an application in these languages. Component-based programming using a binary standard such as M...
Article
Full-text available
H/Direct is a foreign-language interface for the purely functional language Haskell. Rather than rely on host-language type signatures, H/Direct compiles Interface Definition Language (IDL) to Haskell stub code that marshals data across the interface. This approach allows Haskell to call both C and COM, and allows a Haskell component to be wrapped...
Article
Full-text available
The expressiveness of higher-order, typed languages such as Haskell or ML makes them an attractive medium in which to write software components. Hitherto, however, their use has been limited by the allor -nothing problem: it is hard to write just part of an application in these languages.
Conference Paper
Full-text available
this paper we adopt style conventions that emphasize when we are dealing with effectful computations. Specifically, all expressions of type IO are written with an explicit do--. In the same vein, values of functional type a -? b are written as lambda-expressions "a -? b. To reflect the influence of the OO style, we will use postfix function applica...
Article
This paper describes a type system for extensible records and variants with flrst-class labels; labels are polymorphic and can be passed as arguments. This in- creases the expressiveness of conventional record calculi signiflcantly, and we show how we can encode intersec- tion types, closed-world overloading, type case, label selective calculi, and...
Article
Functional programming has had a profound impact on the development of mainstream languages such as C# or Java.We wanted to get a better sense of developer's perceptions of functional programming, and also better understand which functional programming concepts are useful to developers. This paper reports the results of a preliminary survey on this...
Article
Version control systems are essential for managing the dis- tributed development of large software projects. We present a formal model for reasoning about version control. In particular, we give a gen- eral definition of patch. Patches abstract over the data on which they operate, making our framework equally suited for version control of ev- eryth...
Article
This article presents an extension to the work of Launchbury and Peyton-Jones on the ST monad. Using a novel model for concurrency, called concurrent revisions [3, 5], we show how we can use concurrency together with imperative mutable variables, while still being able to safely convert such computations (in the Rev monad) into pure values again. I...
Article
Large and complex software systems, like those common on personal computers, often contain many components that can be deployed separately—applications, libraries, drivers, etc.—but that must then be bound together into working configurations. Configuring software is difficult and error-prone in practice, and it is not well understood in theory. As...
Article
Most programming languages in use today let one freely use arbitrary (side) effects. This is despite the fact that unknown and unre-stricted side effects are the cause of many software problems. We propose a programming model where effects are treated in a disciplined way, and where the potential side-effects of a function are apparent in its type...

Citations

... As shown by Piróg et al. [46], there exists a pair of macro translations [23] between control0/prompt0 and shallow effect handlers [30]. Therefore, a good understanding of control0/prompt0 would serve as a stepping stone to a better implementation of shallow handlers, which has not yet been fully explored [55,56]. ...
... In Swiftlet, intermediate structures can be removed altogether using inout to perform in-place part-wise mutation, or by relying on optimizations to substitute aliases for copies (Section 6). Reinking et al. (2021) advocate for the use of reference counting as an automatic garbage collection mechanism to allow efficient in-place updates of unique data structures, using borrowed references to reduce reference counter updates (Ullrich & de Moura 2019). Unlike our naive implementation of copy-on-write, their framework is able to generate faster code paths when reference counts can be tracked statically. ...
... The library also implements pairing of runners from Example 12, e.g., to combine state and input-output. We also use the library to demonstrate that ambient functions from the Koka language [16] can be implemented with runners by treating their binding and application as co-operations. (These are functions that are bound dynamically but evaluated in the lexical scope of their binding.) ...
... Effect handlers evidently [Xie et al. 2020] shows obtain efficient run times of algebraic effect handlers, by translating effect handlers to multi-prompt delimited continuations [Felleisen 1988;Gunter et al. 1995]. The translation of Xie et al. [2020] restricts effect handlers to use scoped resumptions; i.e., continuation values should not escape their handlers. ...
... Applications like database engines, stock trading systems, or web browsers use custom memory allocators [4], [5]. A variety of allocators exist: jemalloc [6], mimalloc [7], rpmalloc [8], snmalloc [9], and tcmalloc [10]. We observe that both industry and open-source software projects tend to use either jemalloc (currently mainly developed by Facebook) or tcmalloc (developed by Google). ...
... Our effect system rules out some use cases of multi-prompt delimited control (Kobori et al., 2016), but can express many interesting use cases of effect handlers. • We present our API design of ambient state (Kiselyov et al., 2006;Leijen, 2018) as the second of the two built-in effects: the State effect. • We evaluate the usability of our library in multiple extended case studies. ...
... This can be useful if no synchronization is necessary between the produced output and downstream reactions that observe it. One can compare this sort of interaction with the handling of events in JavaScript [149]; when an event occurs, it will be pushed onto a queue and handled later, in some arbitrary order. In other words, physical connections are a mechanism for intentionally introducing nondeterminism in places where no strict ordering of events is required. ...
... While OCaml permits throwing exceptions across C frames, we do not allow effects to propagate across C frames as the C frames would become part of the captured continuation. Managing C frames as part of the continuation is a complex endeavour [33], and we find that the complexity budget outweighs the relatively fewer mechanisms enabled by this addition in our setting. ...
... This includes event-driven programming models where events have similar semantics to that of promises. JavaScript, though a single-threaded language, still uses an asynchronous task model to schedule callbacks on an event loop [39], and could benefit from our approach. Likewise, our approach is directly applicable to multithreaded execution models, such as Concurrent Collections [8] and the Open Community Runtime [41], that use event-driven execution as a fundamental primitive. ...
... There are many flavors of control operators that capture the continuation and give programmers the choice to resume computation, perhaps multiple times, or discard the continuation and abort [Danvy and Filinski 1990;Dybvig et al. 2007;Felleisen 1988;Sitaram and Felleisen 1990]. They are useful for structuring programs with complex control flow and can express a large number of useful idioms [Haynes 1987;Hieb and Dybvig 1990;Leijen 2017]. Figure 12 extends Λ with an operator for delimited control (Λ [Shf]). ...