Type Inference

How Jot infers types, reports errors, and where explicit annotations are most useful.

Jot uses Hindley-Milner style inference to resolve most types automatically at compile time.

What this gives you

  • Fewer required annotations in everyday code.
  • Compile-time errors when assumptions do not unify.
  • Polymorphic helpers without boilerplate signatures in every local binding.

How inference works

  1. The compiler assigns type variables to expressions.
  2. Constraints are collected from usage (calls, operators, returns, bindings).
  3. Unification solves those constraints into one consistent type shape.

When constraints conflict, compilation fails with a type error before execution.

When to annotate

Inference is strong, but explicit types still help at boundaries:

  • Public function signatures
  • Module exports
  • Interop surfaces
fn parsePort(input: String) -> Int {
  // ...
}

Practical outcome

You keep fast iteration and concise code while still getting strict static guarantees.