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

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.

主站蜘蛛池模板: 辽源市| 神农架林区| 尚志市| 宝兴县| 资源县| 长沙市| 呼图壁县| 沙坪坝区| 温州市| 邵武市| 卓资县| 隆德县| 神农架林区| 三明市| 台江县| 固阳县| 德兴市| 石渠县| 伊金霍洛旗| 茌平县| 普格县| 抚松县| 黄骅市| 海安县| 西丰县| 烟台市| 新泰市| 汝州市| 钟祥市| 沐川县| 定西市| 定州市| 清苑县| 九寨沟县| 绵竹市| 巫溪县| 平陆县| 嘉义市| 汉源县| 乌拉特前旗| 吉木乃县|