一句话:提出静态类型的组合式编程风格与 CP 语言,用组合式接口、trait、方法模式等概念同时解决表达式问题与模块化依赖。
模块性与可扩展性一直是编程语言的核心难题:表达式问题(EP)揭示了大多数语言只能在新增变体与新增操作之间二选一,而以模块化方式表达复杂依赖同样困难。本文提出一种新的静态类型模块化编程风格——组合式编程(Compositional Programming)。该风格从根本上消解了 EP:可以同时在多个维度上扩展,既能方便地新增变体,也能方便地新增操作。它提供了一条不同于函数式代数数据类型与面向对象类层次的建模路径,并引入四个关键概念:组合式接口、组合式 trait、方法模式与嵌套 trait 组合。基于这些概念,作者设计了语言 CP,可用于建模类似属性文法的程序,并自然地处理具有复杂依赖的模块化程序,文中通过多个示例与三个案例研究进行说明,并证明了该语言是类型安全的。
Modularity is a key concern in programming. However, programming languages remain limited in terms of modularity and extensibility. Small canonical problems, such as the Expression Problem (EP), illustrate some of the basic issues: the dilemma between choosing one kind of extensibility over another one in most programming languages. Other problems, such as how to express dependencies in a modular way, add up to the basic issues and remain a significant challenge. This article presents a new statically typed modular programming style called Compositional Programming . In Compositional Programming, there is no EP: It is easy to get extensibility in multiple dimensions (i.e., it is easy to add new variants as well as new operations). Compositional Programming offers an alternative way to model data structures that differs from both algebraic datatypes in functional programming and conventional OOP class hierarchies. We introduce four key concepts for Compositional Programming: compositional interfaces , compositional traits , method patterns , and nested trait composition . Altogether, these concepts allow us to naturally solve challenges such as the Expression Problem, model attribute-grammar-like programs, and generally deal with modular programs with complex dependencies . We present a language design, called CP , which is proved to be type-safe, together with several examples and three case studies.