一句话:提出 OO 语言 Num,分离对象数量与类型,统一处理零/一/多对象,并用 plural method 取代静态方法。
多数面向对象语言要求用特殊构造把零个或多个对象编码成单值,以处理无对象或多对象情形。本文主张让表达式直接求值为任意数量对象,并提出核心面向对象语言 Num。Num 将数量与类型分离,表达式类型不取决于对象数量,从而统一处理零、一、多对象;它取消 null 引用,用可数性替代引用类型的可空性,并允许在任意数量接收者(含零个)上调用方法。为适应实际接收者数量,Num 在实例方法外引入 plural method,对多个对象联合操作并取代静态方法。作者给出 Num 的 Prolog 实现及类型安全与数量安全证明,作为概念验证。
To let expressions evaluate to no or many objects, most object-oriented programming languages require the use of special constructs that encode these cases as single objects or values. While the requirement to treat these standard situations idiomatically seems to be broadly accepted, I argue that its alternative, letting expressions evaluate to any number of objects directly, has several advantages that make it worthy of consideration. As a proof of concept, I present a core object-oriented programming language, dubbed Num , which separates number from type so that the type of an expression is independent of the number of objects it may evaluate to, thus removing one major obstacle to using no, one, and many objects uniformly. Furthermore, Num abandons null references, replaces the nullability of reference types with the more general notion of countability, and allows methods to be invoked on any number of objects, including no object. To be able to adapt behavior to the actual number of receivers, Num complements instance methods with plural methods, that is, with methods that operate on a number of objects jointly and that replace static methods known from other languages. An implementation of Num in Prolog and accompanying type and number safety proofs are presented.
@article{paperbot1602,
title = {Containerless Plurals: Separating Number from Type in Object-Oriented Programming},
author = {Friedrich Steimann},
journal = {ACM Transactions on Programming Languages and Systems},
volume = {44},
number = {4},
year = {2022},
doi = {10.1145/3527635}
}