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

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.

主站蜘蛛池模板: 罗城| 辉县市| 武义县| 百色市| 宝坻区| 湘西| 皋兰县| 襄垣县| 麻江县| 巴彦淖尔市| 迁安市| 百色市| 苏尼特左旗| 班玛县| 泰州市| 石柱| 芜湖县| 石渠县| 台中市| 密云县| 邵武市| 浦江县| 中卫市| 彭阳县| 乡城县| 丹寨县| 潜山县| 鄢陵县| 新余市| 南通市| 沙雅县| 惠东县| 河南省| 清河县| 石家庄市| 旬阳县| 和龙市| 邯郸市| 通许县| 化州市| 墨脱县|