- 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.
推薦閱讀
- 極簡算法史:從數學到機器的故事
- Python語言程序設計
- 青少年軟件編程基礎與實戰(圖形化編程三級)
- Vue.js快速入門與深入實戰
- Mastering PHP Design Patterns
- Learn Swift by Building Applications
- 零基礎學Java程序設計
- Spring Boot進階:原理、實戰與面試題分析
- Python算法從菜鳥到達人
- Kotlin從基礎到實戰
- Practical Microservices
- Python Deep Learning
- SQL Server on Linux
- Java服務端研發知識圖譜
- C++ Data Structures and Algorithm Design Principles