Value-level programming in Go is what you do most of the time: functions and expressions that operate on values while the program runs. Type-level programming means shaping the types themselves so the compiler enforces rules, using named types, interfaces, constraints and generics. Go supports this in a limited form, and it has no type-level computation like TypeScript conditional types.
Good Go code uses types to rule out mistakes and values to carry data and logic.
At the value level you write statements that execute: arithmetic, loops, function calls and error handling.
Every result here depends on runtime input. Bugs at this level show up as wrong output, errors or panics.
Type-level programming decides what values are allowed, before the program runs. Go gives you several tools.
Both types are int64 underneath, but the compiler refuses to mix them. The rule is enforced at compile time with no run-time cost.
Interfaces describe required behaviour. Constraints, which are interfaces too, can list type sets with | and the tilde form ~.
Abs is written once and works on any integer type, including your own named types. Passing a string fails to compile.
The types carry the relationship between key and value without any casts.
Go has no conditional types, type-level functions, type-level numbers, variadic type parameters or specialisation. Generic code cannot branch on its type parameter at compile time, and methods cannot declare their own type parameters. Generic type aliases are supported from Go 1.24. If you need behaviour per type, use an interface method or a type switch on a value converted to any.
A constructor is a common bridge: a value-level check that returns a type-level guarantee.
The check runs once at run time. After that, functions that accept Email document and signal that validation happened. Keep in mind that Go cannot stop code in the same package from writing Email("bad"), so put the type in its own package with an unexported struct field if you need a strict guarantee.
| Aspect | Value level | Type level |
|---|---|---|
| Concerned with | Data and logic | What data may exist |
| Checked | At run time | At compile time |
| Failure looks like | Error, panic, wrong output | Compile error |
| Tools | Functions, loops, if | Named types, interfaces, generics |
| Cost | CPU and memory | Compile time and some complexity |
Email type built by a constructor that returns an error.Only in simple forms: named types, interfaces and basic generics. Heavy type tricks are discouraged.
Usually not noticeably. The compiler generates efficient code, though the exact result depends on the case, so benchmark when it matters.
int?When the value has a meaning you want the compiler to protect, such as an ID, a unit or a state.
Yes. A constraint can be an interface with methods, so generic functions can call those methods on type parameters.
Value-level code computes with data at run time, and type-level code uses Go types to rule out errors at compile time. Use named types, interfaces and modest generics for the type level, and accept that Go does not compute types.