- Learn Type:Driven Development
- Yawar Amin Kamon Ayeva
- 248字
- 2021-07-02 14:41:25
Types and values
Let's set the stage for the rest of the book with a discussion of types and values. At its core, a type is a set of values. Think of the type bool, which is what Reason calls the normal Boolean type. A bool value can be one of two different things: true or false. We say that these values inhabit (live in) the type. Anything else is an error.
This raises an interesting question: what does it mean to say? Anything else is an error' in this context? In fact, why should we care about types at all?
To answer these questions, let's think about what should happen if we try to do the operation "Bob" / 5. What does it mean to divide the string Bob by the number 5?
If you can't think of a good answer, well neither can anyone else. It's kind of a meaningless question. It's like asking, how does the color green taste? (Although this may be a meaningful question for synesthetic people.)
Anyway, this is the simplest answer to why we care about types – to avoid having to deal with meaningless questions. To rule out meaningless operations, we simply make them type errors in the programs that execute the code. In other words, we get our compilers and interpreters to slot all our values into distinct types, or errors if any operations can't be meaningfully performed for the given types of values.
- Oracle從入門到精通(第3版)
- Learning NServiceBus(Second Edition)
- JavaScript全程指南
- Xcode 7 Essentials(Second Edition)
- OpenCV for Secret Agents
- Practical Game Design
- PLC編程及應用實戰
- 基于Swift語言的iOS App 商業實戰教程
- Visual C#.NET程序設計
- Hands-On Full Stack Development with Go
- Oracle 12c從入門到精通(視頻教學超值版)
- Mastering SciPy
- 數據結構:Python語言描述
- 百萬在線:大型游戲服務端開發
- Tableau Dashboard Cookbook