On this page
Type Systems
Prev: Binary, Numbers & Encodings | Up: data_and_types | Next: Value vs. Reference Semantics
Rel: Python Type Hinting, TypeScript Type System, Error-Handling Philosophies
Ref: Wikipedia โ Type System
Tags: #public #prog #programming #types
Contents
- > Static vs. Dynamic & Strong vs. Weak
- > Nominal vs. Structural Typing
- > Algebraic Data Types (Product & Sum Types)
Static vs. Dynamic & Strong vs. Weak
- Static typing (C, Java, Rust, TypeScript): checks type compatibility before execution (at compile time).
- Dynamic typing (Python, JavaScript): attaches types to runtime values and checks operations when executed.
- Strong vs. weak: describes how freely a language silently coerces incompatible types (e.g.,
"5" + 1errors in Python, coerces to"51"in JavaScript).
Nominal vs. Structural Typing
- Nominal: compatibility requires explicit name/inheritance declaration (
class Dog implements Animal). - Structural ("duck typing"): compatibility depends solely on shape/methods (
Gointerfaces, TypeScript interfaces, PythonProtocol).
Algebraic Data Types (Product & Sum Types)
- Product type (AND โ
struct,record,tuple): holds field A and field B simultaneously; total states = $|A| \times |B|$. - Sum type (OR โ tagged
enum/ discriminated union): holds either variant A or variant B (Result = Ok(T) | Err(E)); total states = $|A| + |B|$. Pairing sum types with exhaustive pattern matching catches missing cases at compile time.
Linked from
- tuts/c/fundamentals/structs_unions_and_enums
- tuts/java/language_and_oop
- tuts/programming/data_and_types
- tuts/programming/data_and_types/binary_numbers_and_encodings
- tuts/programming/data_and_types/type_systems
- tuts/programming/data_and_types/value_vs_reference_semantics
- tuts/programming/paradigms/functional_programming
- tuts/programming/software_design/error_handling_philosophies
- tuts/typescript
- tuts/typescript/type_system
- tuts/typescript/type_system/structural_typing_and_narrowing
Related notes
- tuts/programming/data_and_types Linked here; links to this page; shared tags: #prog, #programming, #types
- tuts/programming/data_and_types/binary_numbers_and_encodings Linked here; links to this page; shared tags: #prog, #programming, #types
- tuts/programming/data_and_types/value_vs_reference_semantics Linked here; links to this page; shared tags: #prog, #programming, #types
- tuts/programming/software_design/error_handling_philosophies Linked here; links to this page; shared tags: #prog, #programming
- tuts/typescript/type_system Linked here; links to this page
- tuts/programming/paradigms/functional_programming links to this page; shared tags: #prog, #programming
- tuts/c/fundamentals/structs_unions_and_enums links to this page; shared tags: #prog
- tuts/java/language_and_oop links to this page; shared tags: #prog
- tuts/python3/tutorials/intermediate_python_and_software_engineering/type_hinting_and_static_analysis Linked here
- tuts/typescript links to this page