> For the complete documentation index, see [llms.txt](https://harmeetsingh.gitbook.io/scala-type-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://harmeetsingh.gitbook.io/scala-type-system/phase-i/chapter-1-what-are-the-types.md).

# Chapter 1: What are the types?

Before we talk about **types**, let's first understand **values**. Values are the raw data that programs work with, such as `2`, `'c'`, `"string"`, `4.3`, and many more. From a mathematical perspective, we can think of values as being infinite, as illustrated in the following diagram.

![](https://lh3.googleusercontent.com/wsgeTnrvAI3-5BXNwbPNdfSdSSCulqCtwvIxidWXVKmJgsCm5hVxBOdBtb225Tn_i1ZOdu8fHEcxzPc8cFV0EpDmljsvkNuiroWjRNeI4wVpIB6M9p2bJG9nPlxkH9avSIN9xaoY)

magine an endless circle containing an infinite number of values. These values can represent anything. To identify and classify them, **types** come into the picture. As we know, many concepts in computer science are derived from mathematics. Based on **set theory** and **simple type theory**, values can be grouped according to their characteristics. These topics are vast and deserve separate discussion, so we will not explore them in detail in this book. Instead, let's divide this endless collection of values into smaller sets based on their associated types.<br>

![](https://lh3.googleusercontent.com/ctBjoowBxb5t_1qIJQDJkf1n1yl-iG4JTMwWStgI-v15BKsPyKj8YUDdZ3xdFF2Q23Dyu0y7YuGW_Mtv_J-Hj64tVKSJMMm-5pWPqZT93eO5yzP3CpttR5Nqesk0jCAh-RCAiAG6)

\
As you can see, we now have separate sets of values, each grouped according to its type. The set of values that belongs to a type is determined by that type itself. For example, the `Int` type contains only integer values within its valid range, while the `String` type represents textual values.<br>

**Daniel Spiewak** explains this concept in his talk, [High Wizardry in the Land of Scala](https://vimeo.com/28793245). He illustrates the relationship between types and values using the following diagram:

![](https://lh4.googleusercontent.com/9r3TOtolzm6227F0jNqyYDSF4Ezrybm-stg7zKSWGoeOsMvTkBeGP68ZuoVdCImsNtTb2gldfpVIzhE5CgFL9RBLTo0Rw35okoPzcMgzpHl2LvP_XNsIzSO_lTxvhkyFG1rsNkYC)

The diagram shows that while the number of possible **values** is enormous (or even infinite for some types), the number of **types** is comparatively much smaller. Consider the following Scala example:

```scala
val a: Int = 4
val b: Int = 5

val string: String = “Hello World”
```

In this example, we have **three values** but only **two types** (`Int` and `String`). A single type such as `Int` can represent values ranging from **-2147483648** to **2147483647**. Similarly, a `String` can represent an enormous number of different values, while the type itself remains the same. This is why we can say that **many values can belong to a single type**.

From this discussion, we can think of a **type** as a specialized container that determines what kind of values it can hold. Just as we use different containers for different purposes—a glass, bottle, or bucket for carrying water, and specially designed containers for storing hazardous chemicals—programming languages use types to ensure that values are stored and manipulated appropriately according to their characteristics.
