<commit_before>
# Understanding Types

So far we have kind of glossed over types, but getting comfortable with them is important to learning Elm and will likely help you in other languages as well. Once you make the initial investment in learning this stuff, the benefits are quite crazy.

> **Note:** The term &ldquo;types&rdquo; will be used to mean &ldquo;types as they appear in Elm&rdquo;. This is an important distinction because *types in Elm are very different than types in Java!* Many programmers have only seen types in Java, so their experience is roughly &ldquo;using types is verbose and annoying, and at the end of the day, I still get the same runtime errors and null pointer exceptions as in JavaScript or Python or Ruby. What's the point?!&rdquo; Most Elm programmers share all of these complaints about Java!

I find that types play at least two major roles in my code:

  1. They **rule out runtime errors**. There may be *logical* bugs in a code path (the code does not do what you intended) but there are no *operational* bugs (calling a function that does not exist).
  2. They are a **refactoring assistant**. Whenever I change a core piece of code, Elm can give me a comprehensive list of all the code that is affected. Big refactors are shockingly quick and low-risk.

As you have probably experienced, people who like types can talk about the benefits all day, so I'll spare you any more! The best way to convey this stuff is for you to experience it yourself in a reasonably sized application, so let's get started!


## Primitives

The basic building blocks of Elm are a set of primitive values that include strings, booleans, and numbers. For example, the number 42 is an integer. So to write down the type we say:

```haskell
42 : Int
```

This is read, &ldquo;42 has type `Int`&rdquo;. The term `Int` is the abbreviation for integers. The same works for all types of primitive values:

```haskell
True    : Bool      -- True is a boolean value
3.1415  : Float     -- pi is a floating point number
'x'     : Char      -- 'x' is a character
"Alice" : String    -- "Alice" is a string of characters
```

You would read each entry as &ldquo;True has type Bool&rdquo;, &ldquo;3.1415 has type float&rdquo;, etc. The basic types are all slightly abbreviated, and this convention has become so widespread in programming languages that there is no going back. It may be confusing at first, but it turns out to be quite nice.

One thing to note, a floating point number is any number with a decimal point. Its name reflects some of its technical details, but they are not super important. The main thing to know is that a `Float` is not 100% accurate, at some point it stops keeping track of very, very small fractions. It is also important to know that an `Int` and a `Float` are not the same thing! They are both numbers, but they are represented differently and have different properties.
<commit_msg>Minor wording changes in intro<commit_after>
# Understanding Types

So far we have kind of glossed over types, but getting comfortable with them is important to learning Elm and will likely help you in other languages as well. Once you make the initial investment in learning this stuff, the benefits are quite crazy.

> **Note:** The term &ldquo;types&rdquo; will be used to mean &ldquo;types as they appear in Elm&rdquo;. This is an important distinction because *types in Elm are very different than types in Java!* Many programmers have only seen types in Java, so their experience is roughly &ldquo;using types is verbose and annoying, and at the end of the day, I still get the same runtime errors and null pointer exceptions as in JavaScript or Python or Ruby. What's the point?!&rdquo; Most Elm programmers share all of these complaints about Java!

I find that types play at least two major roles in my code:

  1. They **rule out runtime errors**. In practice, you just do not get any in Elm, it is pretty crazy. There may be *logical* bugs in a code path (the code does not do what you intended) but there are no *operational* bugs (calling a function that does not exist).
  2. They are a **refactoring assistant**. Whenever I change a core piece of code, Elm can give me a comprehensive list of all the code that is affected. Big refactors are shockingly quick and low-risk.

As you have probably experienced, people who like types can talk about the benefits all day, so I'll spare you any more! The best way to convey this stuff is for you to experience it yourself in a decent-sized code-base, so let's get started!


## Primitives

The basic building blocks of Elm are a set of primitive values that include strings, booleans, and numbers. For example, the number 42 is an integer. So to write down the type we say:

```haskell
42 : Int
```

This is read, &ldquo;42 has type `Int`&rdquo;. The term `Int` is the abbreviation for integers. The same works for all types of primitive values:

```haskell
True    : Bool      -- True is a boolean value
3.1415  : Float     -- pi is a floating point number
'x'     : Char      -- 'x' is a character
"Alice" : String    -- "Alice" is a string of characters
```

You would read each entry as &ldquo;True has type Bool&rdquo;, &ldquo;3.1415 has type float&rdquo;, etc. The basic types are all slightly abbreviated, and this convention has become so widespread in programming languages that there is no going back. It may be confusing at first, but it turns out to be quite nice.

One thing to note, a floating point number is any number with a decimal point. Its name reflects some of its technical details, but they are not super important. The main thing to know is that a `Float` is not 100% accurate, at some point it stops keeping track of very, very small fractions. It is also important to know that an `Int` and a `Float` are not the same thing! They are both numbers, but they are represented differently and have different properties.

{'fraction_non_alphanumeric': 0.0541497975708502, 'fraction_numerical': 0.00708502024291498, 'mean_word_length': 4.011834319526627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1999362', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1468, 'n_words': 1001}