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

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.

主站蜘蛛池模板: 信宜市| 农安县| 博湖县| 莎车县| 五家渠市| 福清市| 富裕县| 治县。| 延长县| 宁晋县| 钟祥市| 安庆市| 寿宁县| 南雄市| 梅河口市| 乌拉特后旗| 咸宁市| 徐水县| 石首市| 宁波市| 新疆| 东台市| 罗定市| 北川| 广丰县| 梓潼县| 兴安盟| 乐东| 松江区| 广东省| 莲花县| 东乌| 洛浦县| 霍邱县| 津市市| 贡山| 甘谷县| 阿克陶县| 华池县| 清新县| 宝清县|