Many object-oriented dynamic languages allow programmers to extract methods from objects and treat them as functions. This allows for flexible programming patterns, but presents challenges for type systems. In particular, a simple treatment of method extraction would require methods to be contravariant in the receiver type, making overriding all-but-impossible. We present a detailed investigation of this problem, as well as an implemented and evaluated solution. Method extraction is a feature of many dynamically-typed and gradually-typed languages, ranging from Python and PHP to Flow and TypeScript. In these languages, the underlying representation of objects as records of procedures can be accessed, and the procedures that implement methods can be reified as functions that can be called independently. In many of these languages, the programmer can then explicitly specify the this value to be used when the method implementation is called. Unfortunately, as we show, existing gradual type systems such as TypeScript and Flow are unsound in the presence of method extraction. The problem for typing any such system is that the flexibility it allows must be tamed by requiring a connection between the object the method was extracted from, and the function value that is later called. In Racket, where a method extraction-like facility, dubbed "structure type properties", is fundamental to classes, generic methods, and other APIs, these same challenges arise, and must be solved to support this feature in Typed Racket. We show how to combine two existing type system features-existential types and occurrence typing-to produce a sound approach to typing method extraction...


翻译:许多面向目标的动态语言允许程序员从对象中提取方法,并将之作为函数处理。这允许灵活的编程模式,但给类型系统带来挑战。特别是,对方法提取的简单处理要求方法在接收器类型中具有反向性,从而压倒一切但不可能。我们对这一问题进行了详细调查,并提出了一种实施和评估的解决办法。方法提取是许多动态类型和逐步类型语言的特点,从Python和PHP到流程和类型Script。在这些语言中,可以访问作为程序记录的对象的基本表述,而执行方法的特性可以被重新确定为可独立调用的职能。在许多这类语言中,程序员可以明确指定在要求方法实施时使用的这一价值。不幸的是,正如我们所显示的那样,在方法提取过程中,像 TypeScript 和流动这样的渐进类型系统是不可靠的。输入任何这种系统的问题在于,它允许的灵活性必须被调制成一个像系统之间的连接,而执行方法的特性可以被重新配置为函数。在类中,在类型中,提取方法的类型和排序中, 和排序中, 将生成一种基本方法的排序中, 将生成到排序到排序到排序中, 将生成到排序到排序中, 将生成到排序中, 将产生一种方法到排序到排序到排序到排序到排序到排序到排序到排序到排序到排序到排序到排序中, 。

0
下载
关闭预览

相关内容

TypeScript is a language for application-scale JavaScript development.TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. typescriptlang.org/
最新《自监督表示学习》报告,70页ppt
专知会员服务
85+阅读 · 2020年12月22日
专知会员服务
123+阅读 · 2020年9月8日
Linux导论,Introduction to Linux,96页ppt
专知会员服务
76+阅读 · 2020年7月26日
Keras François Chollet 《Deep Learning with Python 》, 386页pdf
专知会员服务
144+阅读 · 2019年10月12日
强化学习最新教程,17页pdf
专知会员服务
168+阅读 · 2019年10月11日
【新书】Python编程基础,669页pdf
专知会员服务
186+阅读 · 2019年10月10日
机器学习入门的经验与建议
专知会员服务
90+阅读 · 2019年10月10日
已删除
将门创投
4+阅读 · 2019年5月8日
论文浅尝 | Global Relation Embedding for Relation Extraction
开放知识图谱
12+阅读 · 2019年3月3日
逆强化学习-学习人先验的动机
CreateAMind
15+阅读 · 2019年1月18日
Unsupervised Learning via Meta-Learning
CreateAMind
41+阅读 · 2019年1月3日
A Technical Overview of AI & ML in 2018 & Trends for 2019
待字闺中
16+阅读 · 2018年12月24日
Hierarchical Disentangled Representations
CreateAMind
4+阅读 · 2018年4月15日
Capsule Networks解析
机器学习研究会
10+阅读 · 2017年11月12日
【论文】图上的表示学习综述
机器学习研究会
12+阅读 · 2017年9月24日
Arxiv
0+阅读 · 2021年10月1日
Arxiv
3+阅读 · 2019年3月1日
Arxiv
10+阅读 · 2017年7月4日
VIP会员
相关VIP内容
最新《自监督表示学习》报告,70页ppt
专知会员服务
85+阅读 · 2020年12月22日
专知会员服务
123+阅读 · 2020年9月8日
Linux导论,Introduction to Linux,96页ppt
专知会员服务
76+阅读 · 2020年7月26日
Keras François Chollet 《Deep Learning with Python 》, 386页pdf
专知会员服务
144+阅读 · 2019年10月12日
强化学习最新教程,17页pdf
专知会员服务
168+阅读 · 2019年10月11日
【新书】Python编程基础,669页pdf
专知会员服务
186+阅读 · 2019年10月10日
机器学习入门的经验与建议
专知会员服务
90+阅读 · 2019年10月10日
相关资讯
已删除
将门创投
4+阅读 · 2019年5月8日
论文浅尝 | Global Relation Embedding for Relation Extraction
开放知识图谱
12+阅读 · 2019年3月3日
逆强化学习-学习人先验的动机
CreateAMind
15+阅读 · 2019年1月18日
Unsupervised Learning via Meta-Learning
CreateAMind
41+阅读 · 2019年1月3日
A Technical Overview of AI & ML in 2018 & Trends for 2019
待字闺中
16+阅读 · 2018年12月24日
Hierarchical Disentangled Representations
CreateAMind
4+阅读 · 2018年4月15日
Capsule Networks解析
机器学习研究会
10+阅读 · 2017年11月12日
【论文】图上的表示学习综述
机器学习研究会
12+阅读 · 2017年9月24日
Top
微信扫码咨询专知VIP会员