Type Inference
A compiler deriving a value's type from how it's used, so a programmer doesn't have to write it down.
Type Inference is a compiler's ability to determine an expression's type from context — its literal form, the functions applied to it, how its result is used — without an explicit type annotation. let x = 5 in a statically typed inferred language like Rust or Haskell needs no : number; the compiler sees the literal, assigns i32 (or generalizes it, in Haskell's case, to whatever numeric type the rest of the program constrains it to be).
The classical algorithm is Hindley-Milner, which infers the most general type consistent with a program's constraints by walking the syntax tree, generating type variables for unknowns, and unifying them against each use — two uses of the same variable in incompatible ways produce a type error even though nobody wrote a type anywhere. This is why ML-family languages (OCaml, Haskell, F#) can be almost entirely unannotated and still be fully statically typed: the annotations are optional documentation, not a requirement for soundness.
Inference is easy to conflate with dynamic typing or Duck Typing, but the two are opposites on the axis that matters: an inferred type is still checked at compile time and still rejects a mismatched program before it runs, it's only the spelling of the type that's optional, not the checking of it. TypeScript's let x = 5; x = "hi" is a compile error via inference the same way an explicitly annotated let x: number would be.
The trade-off inference introduces is an error message pointing to where a constraint was violated rather than where the mismatched value was introduced, since inference propagates constraints forward from every use site — a single wrong argument several calls upstream can surface as a confusing type error deep inside unrelated code, which is the usual complaint leveled at Haskell's compiler.
See also6
Pattern Matching
Testing a value against a shape and binding its parts to names in one step, instead of inspecting it field by field.
Computation & Algorithms7 connections
Schema Validation
Checking data against a declared shape at runtime, and using the result as the typed value.
Agents & Language Models22 connections
Compiler
A program that translates source code into another form, ahead of running it, checking it along the way.
Computation & Algorithms11 connections
TypeScript
Microsoft's typed superset of JavaScript, whose types are checked at build time and erased at runtime, and the deliberate trade-offs that made it the default for large web codebases.
Web Platform8 connections
Type System
The rules a language uses to classify values and reject operations that don't fit, checked before the program runs or as it runs, and the cheapest form of verification most programmers use every day.
Testing & Verification12 connections
Generics
Writing code once over a type variable so it works for any type, how languages implement it by erasure or by copying, and what constraints on type parameters buy.
Computation & Algorithms7 connections
Linked from9
- CompilerComputation & Algorithms
A program that translates source code into another form, ahead of running it, checking it along the way.
- Duck TypingComputation & Algorithms
Treating an object as suitable for a role based on what it can do, not what type it's declared to be.
- GenericsComputation & Algorithms
Writing code once over a type variable so it works for any type, how languages implement it by erasure or by copying, and what constraints on type parameters buy.
- InterpreterComputation & Algorithms
A program that executes source code directly, statement by statement, without a separate translation step first.
- Pattern MatchingComputation & Algorithms
Testing a value against a shape and binding its parts to names in one step, instead of inspecting it field by field.
- ReflectionComputation & Algorithms
A program inspecting or modifying its own structure — types, methods, fields — while it runs.
- Static AnalysisTesting & Verification
Finding bugs by examining code without running it, from linters and type checkers to deep security analysis, always trading missed bugs against false alarms.
- Type SystemTesting & Verification
The rules a language uses to classify values and reject operations that don't fit, checked before the program runs or as it runs, and the cheapest form of verification most programmers use every day.
- TypeScriptWeb Platform
Microsoft's typed superset of JavaScript, whose types are checked at build time and erased at runtime, and the deliberate trade-offs that made it the default for large web codebases.