使用多重分派的数组运算符:动态语言中数组实现的设计方法
Array operators using multiple dispatch: a design methodology for array implementations in dynamic languages
摘要:
数组是如此丰富和基本的数据类型,以至于它们往往被内置到语言中,无论是在编译器中还是在大型低级库中。相反,在用户级别定义此功能可以为语言设计者没有预见到的应用程序域提供更大的灵活性。只有少数语言,如C++和Haskell,提供了定义$n$维数组的必要能力,但这些系统依赖于编译时抽象,牺牲了一些灵活性。相比之下,动态语言使用户可以直接定义他们可能想要的任何行为,但可能会牺牲性能。作为Julia语言项目的一部分,我们开发了一种方法,在灵活性和编译时分析之间产生一种新的权衡。我们使用的核心抽象是多重分派。我们已经开始相信,虽然多重分派在大多数编程中并不特别流行,但技术计算是它的杀手级应用。通过使用多方法签名来表达关键函数(如数组索引),可以获得令人惊讶的行为范围,其方式既相对容易编写,又适合编译器分析。这些方法提供的关注点的紧凑分解使得用户定义类型更容易与标准库中的类型保持一致。
英文摘要:
Arrays are such a rich and fundamental data type that they tend to be built into a language, either in the compiler or in a large low-level library. Defining this functionality at the user level instead provides greater flexibility for application domains not envisioned by the language designer. Only a few languages, such as C++ and Haskell, provide the necessary power to define $n$-dimensional arrays, but these systems rely on compile-time abstraction, sacrificing some flexibility. In contrast, dynamic languages make it straightforward for the user to define any behavior they might want, but at the possible expense of performance. As part of the Julia language project, we have developed an approach that yields a novel trade-off between flexibility and compile-time analysis. The core abstraction we use is multiple dispatch. We have come to believe that while multiple dispatch has not been especially popular in most kinds of programming, technical computing is its killer application. By expressing key functions such as array indexing using multi-method signatures, a surprising range of behaviors can be obtained, in a way that is both relatively easy to write and amenable to compiler analysis. The compact factoring of concerns provided by these methods makes it easier for user-defined types to behave consistently with types in the standard library.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。