Resource Polymorphism Guillaume Munch-Maccagnoni (Inria, LS2N CNRS)
[email protected] 6th March 2018 We present a resource-management model for ML-style programming languages, designed to be compatible with the OCaml philosophy and runtime model. This is a proposal to extend the OCaml language with destructors, move semantics, and re- source polymorphism, to improve its safety, efficiency, interoperability, and express- iveness. It builds on the ownership-and-borrowing models of systems programming languages (Cyclone, C++11, Rust) and on linear types in functional programming (Linear Lisp, Clean, Alms). It continues a synthesis of resources from systems pro- gramming and resources in linear logic initiated by Baker. It is a combination of many known and some new ideas. On the novel side, it highlights the good mathematical structure of Stroustrup’s “Resource acquisition is initialisation” (RAII) idiom for resource management based on destructors, a notion sometimes confused with finalizers, and builds on it a notion of resource polymorph- ism, inspired by polarisation in proof theory, that mixes C++’s RAII and a tracing garbage collector (GC). In particular, it proposes to identify the types of GCed values with types with trivial destructor: from this definition it deduces a model in which GC is the default allocation mode, and where GCed values can be used without restriction both in owning and borrowing contexts. The proposal targets a new spot in the design space, with an automatic and pre- dictable resource-management model, at the same time based on lightweight and expressive language abstractions. It is backwards-compatible: current code is ex- pected to run with the same performance, the new abstractions fully combine with the current ones, and it supports a resource-polymorphic extension of libraries.