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

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.

主站蜘蛛池模板: 赣榆县| 股票| 浦江县| 拜城县| 古交市| 铁岭县| 鲁山县| 阳江市| 揭阳市| 潮州市| 瓦房店市| 南投县| 民勤县| 溧阳市| 克什克腾旗| 保德县| 旬邑县| 浦县| 丹阳市| 五峰| 增城市| 福鼎市| 汽车| 临澧县| 新巴尔虎右旗| 和龙市| 大石桥市| 三台县| 叙永县| 平陆县| 怀远县| 西充县| 东丽区| 洮南市| 南阳市| 鄯善县| 宝清县| 藁城市| 永靖县| 玉树县| 土默特左旗|