简体   繁体   中英

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. 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. 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.

A path dependent type is a type with a path, for example 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 .

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. For the example using literal-based types, the compiler needs to be extended to know what the + operation on integer means.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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