Pattern synonyms

Pattern synonyms
复制标题

模式同义词

DOI:
10.1145/2976002.2976013
复制
发表时间:
2016
期刊:
Proceedings of the 9th International Symposium on Haskell
影响因子:
--
通讯作者:
R. Eisenberg
R. Eisenberg
中科院分区:
--
文献类型:
--
作者:
Matthew Pickering;Gergo Érdi;S. Jones;R. Eisenberg

文献摘要

被引文献

相似文献

模式匹配已被证明是一种方便的、富有表现力的数据检查方法。然而,这种语言特性在其传统形式中是有限的:模式必须是具体数据类型的数据构造器。不允许计算或抽象。所讨论的数据类型必须是具体的,不能强制执行任何不变量。此数据类型的任何更改都需要所有客户端更新其代码。本文介绍了模式同义词,它允许程序员抽象模式,弥补上面列出的所有缺点。模式同义词是指定的类型,使编译器能够独立于同义词的定义来检查其有效性。这些类型是复杂的;详细说明如何将类型分配给模式同义词是这项工作的关键贡献。我们已经在格拉斯哥Haskell编译器中实现了模式同义词,在那里它们立即受到欢迎,但是我们相信这个特性可以很容易地导出到支持模式匹配的其他语言中。
Pattern matching has proven to be a convenient, expressive way of inspecting data. Yet this language feature, in its traditional form, is limited: patterns must be data constructors of concrete data types. No computation or abstraction is allowed. The data type in question must be concrete, with no ability to enforce any invariants. Any change in this data type requires all clients to update their code. This paper introduces pattern synonyms, which allow programmers to abstract over patterns, painting over all the shortcomings listed above. Pattern synonyms are assigned types, enabling a compiler to check the validity of a synonym independent of its definition. These types are intricate; detailing how to assign a type to a pattern synonym is a key contribution of this work. We have implemented pattern synonyms in the Glasgow Haskell Compiler, where they have enjoyed immediate popularity, but we believe this feature could easily be exported to other languages that support pattern matching.