为什么 Scala 有路径依赖类型?
我一直在对路径依赖类型进行一些研究。我能找到的最好的描述是:
如果 L 是类型标签,则 xL 和 yL 是相同类型,当且仅当 x 和 y 可以显示为引用同一对象时。
有时这不是人们所期望的子类型行为。我希望如果上面例子中的 L 确实相同,那么就足以使 xL 和 yL 相同。
Scala 如此设计有什么特殊原因吗?
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 x.L and y.L are the same type iff x and y can be shown to refer to the same object.
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 x.L and y.L indentical.
Is there any particular reason why Scala was designed this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可扩展组件抽象论文对路径依赖类型有很好的解释,并且第 3 节中的一个很好的例子:“案例研究:主体/观察者”。
The Scalable Component Abstractions paper has a good explanation on path dependent types and also a good example in Section 3: "Case study: subject/observer".
这篇论文很好地解释了这一点。基本上,它们用于支持基于抽象数据类型的编程和模块化。
This paper explains it nicely. Basically, they're used to support abstract data type based programming and modularization.
将 L 视为泛型类的类型参数。 Scala 夸耀其类型成员,但底层 JVM 仍然具有相同的限制。
Think about L as about type argument of generic class. Scala boasts about its type members but underlying JVM still has the same limitations.