开发者

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 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.开发者_StackOverflow社区 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?


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.


Think about L as about type argument of generic class. Scala boasts about its type members but underlying JVM still has the same limitations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜