- 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.
推薦閱讀
- UNIX編程藝術
- C++ Primer習題集(第5版)
- Spring Boot開發與測試實戰
- C++程序設計(第3版)
- Python快樂編程:人工智能深度學習基礎
- Fundamentals of Linux
- 看透JavaScript:原理、方法與實踐
- PHP+MySQL網站開發技術項目式教程(第2版)
- Learn Swift by Building Applications
- Hands-On Microservices with Kotlin
- 概率成形編碼調制技術理論及應用
- JavaScript 程序設計案例教程
- Building an RPG with Unity 2018
- HTML5從入門到精通 (第2版)
- JavaScript應用開發實踐指南