Types & Values
The problem
Programs manipulate many different kinds of data — numbers, text, true/false — and need to know which operations are valid on each and how much memory each takes. Types answer 'what kind of thing is this and what can I do with it,' turning invalid operations (adding a number to a boolean) into errors caught before or during execution rather than silent nonsense.
Why now
Sets and logic gave the abstract vocabulary for grouping things and reasoning about truth, but said nothing about how a computer actually stores and distinguishes a number from text from a boolean at runtime. A type is that missing piece: a named, concrete set of representable values plus the operations defined over them.
Mental model
A type is a labeled set: 'number' is the set of representable numeric values, 'boolean' is the two-element set {true, false}. Type-checking a program is asking, for every value, 'is this a member of the set its context expects?' — the exact question sets-and-logic already taught you to ask, now applied at compile- or run-time.
Requires
- Sets & LogicMathematical Thinking
A type is formally a named set of possible values; checking that a value 'has' a type is exactly the set-membership question sets-and-logic introduces.
Helps
- Number Systems & BasesMathematical Thinking
Numeric types (int, float) are ultimately binary representations with fixed width; understanding bases explains why integers overflow and floats lose precision, though you can use types without this yet.
Unlocks
Used in
- Static type systems (TypeScript, Rust, Java) that reject invalid programs before they run
- Dynamic type systems (Python, JavaScript) that check membership at runtime instead
- Database column types (INTEGER, VARCHAR, BOOLEAN) enforcing the same idea at the storage layer
- API schemas (JSON Schema, Protobuf) that define valid value sets for network data
Projects
- Write a tiny 'type checker' function that inspects a JS value and reports whether it matches an expected type string
- Deliberately trigger and explain three different type errors in a language of your choice (e.g. TypeScript) and fix each
Examples
- TypeScript: let x: number = 5 declares x as a member of the number type-set
- A boolean is literally the two-element set {true, false} — the smallest possible type
Resources
Mastery checklist
- I can explain what a type is in terms of sets and membership
- I can name the core primitive types in a language I use and their representable value sets
- I can explain the practical difference between static and dynamic type checking
- I can predict and explain a type error before running the code