Papers
Topics
Authors
Recent
Search
2000 character limit reached

Deriving Dependently-Typed OOP from First Principles -- Extended Version with Additional Appendices

Published 11 Mar 2024 in cs.PL | (2403.06707v1)

Abstract: The expression problem describes how most types can easily be extended with new ways to produce the type or new ways to consume the type, but not both. When abstract syntax trees are defined as an algebraic data type, for example, they can easily be extended with new consumers, such as print or eval, but adding a new constructor requires the modification of all existing pattern matches. The expression problem is one way to elucidate the difference between functional or data-oriented programs (easily extendable by new consumers) and object-oriented programs (easily extendable by new producers). This difference between programs which are extensible by new producers or new consumers also exists for dependently typed programming, but with one core difference: Dependently-typed programming almost exclusively follows the functional programming model and not the object-oriented model, which leaves an interesting space in the programming language landscape unexplored. In this paper, we explore the field of dependently-typed object-oriented programming by deriving it from first principles using the principle of duality. That is, we do not extend an existing object-oriented formalism with dependent types in an ad-hoc fashion, but instead start from a familiar data-oriented language and derive its dual fragment by the systematic use of defunctionalization and refunctionalization. Our central contribution is a dependently typed calculus which contains two dual language fragments. We provide type- and semantics-preserving transformations between these two language fragments: defunctionalization and refunctionalization. We have implemented this language and these transformations and use this implementation to explain the various ways in which constructions in dependently typed programming can be explained as special instances of the phenomenon of duality.

Summary

  • The paper demonstrates a systematic derivation of dependently-typed OOP using defunctionalization and refunctionalization, bridging functional and object-oriented paradigms.
  • It presents a novel calculus that leverages the duality between data and codata to enhance extensibility in large-scale dependently-typed systems.
  • Case studies, including a dependently typed web server and a formal treatment of the proof expression problem, illustrate practical modular improvements.

Deriving Dependently-Typed OOP from First Principles

The paper "Deriving Dependently-Typed OOP from First Principles" by David Binder, Ingo Skupin, Tim Süberkrüb, and Klaus Ostermann presents a novel approach to incorporating object-oriented principles in dependently-typed programming languages. The authors address the inherent extensibility challenges associated with dependently-typed functional programming and propose a systematic method to derive a dependently-typed object-oriented calculus from first principles.

Introduction and Motivation

Dependently-typed programming languages primarily follow the functional programming paradigm, which models domains using algebraic data types and pattern matching. Conversely, object-oriented programming represents domains through classes and interfaces, emphasizing extensibility by adding new producers. This paper argues that dependently-typed languages can benefit from including object-oriented features to enhance the extensibility and expressiveness of large programs. The expression problem, which showcases the dichotomy between functional and object-oriented extensibility, underscores this necessity.

Methodology: Defunctionalization and Refunctionalization

The core contribution of the paper is the development of a dependently-typed calculus accommodating both functional and object-oriented fragments. The authors utilize defunctionalization and refunctionalization techniques to derive the object-oriented fragment systematically. These transformations, originally pioneered by Reynolds and later expanded, enable the conversion between higher-order functions and first-order representations, preserving type and semantics.

  1. Data and Codata Duality: The authors assert that functional programming can be associated with data types, defined by their constructors and pattern matches, while object-oriented programming aligns with codata types, defined by their observations and copattern matches. This duality serves as the basis for their transformations.
  2. Systematic Language Design: To design the object-oriented fragment, the authors present a calculus where types and semantics-preserving transformations, specifically defunctionalization and refunctionalization, guide the introduction of codata types. By transposing the representation matrix of a type, these transformations systematically derive codata from data types and vice versa.

Implementation and Case Studies

The authors provide an implementation of their language and demonstrate its capabilities through case studies, including a dependently typed web server and soundness proofs for expression languages. These examples showcase the extensibility benefits gained by adopting the object-oriented fragment.

  1. Web Server: Initially implemented in a functional style, the web server tracks user sessions and manages HTTP requests. The authors refunctionalize the web server to facilitate the addition of new request methods and routes without modifying existing code extensively. This localizes changes, diminishing the maintenance burden.
  2. Proof Expression Problem: The paper also addresses the proof expression problem in formal verification, illustrating how the object-oriented decomposition simplifies extending formalized languages by new syntax and operations, thereby enhancing modularity.

Theoretical Implications and Future Work

The introduction of dependently-typed object-oriented programming creates new theoretical challenges, such as ensuring termination and productivity, managing universe levels, and addressing variance in type definitions. The authors propose areas for future research, including adapting existing termination-checking methods and extending their framework to support behavioral equality robustly.

Conclusion

The systematic derivation of dependently-typed object-oriented programming presented in this paper opens new avenues for the design of expressive and extensible programming languages. By leveraging duality and systematic transformations, the authors provide a framework that balances the strengths of functional and object-oriented paradigms in the context of dependent types. This work is a significant step towards refining language design principles for future dependently-typed systems, promoting both practical and theoretical advancements.

The research highlights the importance of dual paradigms and provides a structured approach to integrating object-oriented features into dependently-typed languages, addressing critical extensibility and expressiveness challenges in contemporary programming and verification tasks.

Paper to Video (Beta)

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Collections

Sign up for free to add this paper to one or more collections.

Tweets

Sign up for free to view the 12 tweets with 64 likes about this paper.

HackerNews