简体   繁体   English

为什么Scala具有路径依赖类型?

[英]Why does Scala have path-dependent types?

I've been doing some research on path-dependent types. 我一直在研究路径依赖类型。 The best description I could find for it was: 我能找到的最好的描述是:

If L is a type label, then xL and yL are the same type iff x and y can be shown to refer to the same object. 如果L是类型标签,则xL和yL是相同类型iff x和y可以显示为引用同一对象。

This sometimes isn't the subtyping behaviour one would expect. 这有时不是人们所期望的子类型行为。 I would expect that if L in the above example was indeed identical then that would be enough to make xL and yL indentical. 我希望如果上面例子中的L确实相同,那么这足以使xL和yL变得狭窄。

Is there any particular reason why Scala was designed this way? Scala是这样设计的,有什么特别的原因吗?

可扩展组件抽象论文对路径依赖类型有很好的解释,也是第3节中的一个很好的例子:“案例研究:主题/观察者”。

This paper explains it nicely. 本文很好地解释了它。 Basically, they're used to support abstract data type based programming and modularization. 基本上,它们习惯于支持基于抽象数据类型的编程和模块化。

Think about L as about type argument of generic class. 将L视为泛型类的类型参数。 Scala boasts about its type members but underlying JVM still has the same limitations. Scala夸耀其类型成员,但底层JVM仍然具有相同的局限性。

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

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