Yukang's Page

2015-03-07

## Subtyping

subtyping解决的问题是多态，OO的一个基本要素。

we say that S is a subtype of T, written S <: T, to mean that any term of type S can safely be used in a context where a term of type T is expected. This view of subtyping is often called the principle of safe substitution.


## Ascription and Casting

down-cast要复杂一些，而且也可能会导致类型系统的不安全，比如：

channels:

The key observation is that, from the point of view of typing, a communication channel behaves exactly like a reference cell: it can be used for both reading and writing, and, since it is difficult to determine statically which reads correspond to which writes, the only simple way to ensure type safety is to require that all the values passed along the channel must belong to the same type.


subtyping的引入导致分支多的情况下类型检查麻烦，因此引入了Join和Meet的概念，实现可参考代码里面的:

## Case Study: Imperative Objects

OOP作为一种抽象手段，可以让通过接口来隐藏实现，客户端的代码只通过同一个接口才操作各种子类的对象。这里的例子一个子类只是比父类多接口而已。

self的简单是现实需要动态找到对应的method，更高效的实现当然是对象创建好后method table建好。