官术网_书友最值得收藏!

Using types to define domain constraints

We've already seen how simple types can be used to express domain constraints, as discussed in the Path-dependent types section. We implemented a lock that guaranteed at compile time that it is only possible to open and close it with the key created for this specific lock. We will conclude our study of type parameters and higher kinded types with two examples.

The first example will demonstrate an application of phantom types to create another version of the lock, which can guarantee the safety of state transitions at compile time without the use of inheritance.

The second example will show how self-recursive types can help to constrain possible subtyping.

主站蜘蛛池模板: 陆丰市| 普格县| 西华县| 化隆| 随州市| 迭部县| 浮山县| 惠水县| 云霄县| 伊通| 陇南市| 长子县| 景东| 宿松县| 永德县| 赣榆县| 申扎县| 白城市| 广丰县| 宁蒗| 台北市| 江口县| 巴林右旗| 衢州市| 龙海市| 松江区| 临猗县| 三门县| 桦甸市| 木兰县| 扶绥县| 漳平市| 北海市| 陆川县| 囊谦县| 恭城| 柳河县| 呼图壁县| 松原市| 曲沃县| 和龙市|