A binding names a value.
score = 10
player_name = "Priya"
An unannotated numeric origin can stay unresolved while Moth considers eligible exact uses in its function body. If none resolves it, whole-number bindings default to I32 and decimal/exponent bindings to F64. Other values keep their own inferred types.
Write the type when it makes the code clearer or gives the compiler needed context:
score I32 = 10
player_name String = "Priya"
Bindings stay immutable unless you mark them as mutable. An immutable binding can't take a different value later.
A binding gives a value a visible name.
count = 42
ratio F64 = 0.5
Declaration forms
name = value
name Type = value
- A binding must have an initializer.
- Without an annotation, the initializer supplies its shape and numeric-literal family. A retained literal origin can wait for eligible exact receivers in the same body before defaulting.
- An explicit annotation supplies an exact receiving type. Raw literals can materialise directly in it, while already typed values need exact compatibility.
- Ordinary bindings are immutable by default.
= creates a binding when the name is new.- An existing mutable place requires
~ before the whole target for a direct or compound write, as in ~count = 1 or ~point.x += 1.
Numeric inference in a runtime body
Numeric inference stays within one runtime body, including its nested blocks, branches, loops and handlers. Only retained literal origins and the permitted receiving relationships participate. Copies and writes can connect the same origin, but a later use cannot invent a missing shape or infer named arithmetic operands backwards.
This does not add general later-use inference or change a completed value's type. Numeric literals owns the receiving contexts, source-order-independent constraints and fixed I32/F64 defaults.
Compile-time constants use # and are documented separately by Constants and compile-time behaviour.
Binding mode and type
Binding mode is not semantic type identity.
An immutable String binding and a mutable String binding still have the same semantic String type. The binding decides which later operations are permitted.
Scope
A binding is visible in its scope and child scopes unless a language rule creates a narrower visibility boundary.
Moth does not allow a visible name to be redeclared. See the Shadowing section for the exact rule.