简体   繁体   English

路径依赖类型和依赖类型之间有什么区别?

[英]What is the difference between path-dependent types and dependent types?

Scala has path-dependent types, but it is said that Scala doesn't support dependent typing. Scala具有路径依赖类型,但据说Scala不支持依赖类型。 What is the difference between path-dependent types and dependent types? 路径依赖类型和依赖类型之间有什么区别?

As far as I understand, path-dependent types are one kind of dependent types. 据我所知,路径依赖类型是一种依赖类型。

A dependent type is a type that depends on a value. 依赖类型是依赖于值的类型。 A path dependent type is a specific kind of dependent type in which the type depends on a path. 路径依赖类型是特定类型的依赖类型,其中类型取决于路径。

I am not sure if the term "path dependent type" exists outside the Scala community. 我不确定Scala社区之外是否存在术语“路径依赖类型”。 In any case, the question is, what is a path? 无论如何,问题是,路径是什么? For Scala, this is defined in the language specification : basically it's a sequence of selections abc.. on non-variable values. 对于Scala,这是在语言规范中定义的:基本上它是非变量值上的选择序列abc..

A path dependent type is a type with a path, for example aT in 路径依赖类型是具有路径的类型,例如aT in

class A { type T; def f: T }
def f(a: A): a.T = a.f

There are other kinds of dependent types. 还有其他类型的依赖类型。 For example, in Scala, the is a pending proposal to add literal-based types to the language, so that you could write val x: 42.type = 21 + 21 . 例如,在Scala中,这是一个将基于文字的类型添加到语言的待定提议 ,因此您可以编写val x: 42.type = 21 + 21

In order to type check a program that uses dependent types, the type system (and the compiler) needs to know about the semantics of these values and its operations. 为了键入检查使用依赖类型的程序,类型系统(和编译器)需要知道这些值及其操作的语义。 The Scala compiler knows the semantics of selection and can decide whether two paths are the same or not. Scala编译器知道选择的语义,并可以决定两个路径是否相同。 For the example using literal-based types, the compiler needs to be extended to know what the + operation on integer means. 对于使用基于文字的类型的示例,需要扩展编译器以了解整数上的+运算意味着什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM