Operator and syntax

Go constraint approximation and union

In a type set, ~T includes types with underlying type T, where T is its own underlying type and is not an interface. A union combines terms under the type-set restrictions. These are constraint constructs, not runtime operators. Example output: '8'.

Formal Syntax & Structure

go syntaxgo
~T; T1 | T2

Working Example

Example Snippetgo
package main
import (  "fmt")
func double[T ~int | ~int64](n T) T { return n * 2 }func main() {  type Distance int  fmt.Println(double(Distance(4)))}
Go Reference