- Learn Scala Programming
- Slava Schmidt
- 116字
- 2021-06-10 19:35:47
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.
推薦閱讀
- Advanced Quantitative Finance with C++
- C# 7 and .NET Core Cookbook
- Django Design Patterns and Best Practices
- 深入淺出Android Jetpack
- Java程序設計與實踐教程(第2版)
- TypeScript圖形渲染實戰:基于WebGL的3D架構與實現
- Linux命令行與shell腳本編程大全(第4版)
- Java EE 7 Performance Tuning and Optimization
- Getting Started with Gulp
- 深入剖析Java虛擬機:源碼剖析與實例詳解(基礎卷)
- JavaScript程序設計(第2版)
- Everyday Data Structures
- 從零開始學Android開發
- Java并發編程:核心方法與框架
- Learning iOS Security