value, object, contract, and enum — each designed to model a distinct kind of domain concept. This page covers the full syntax, rules, and construction forms for each declaration kind, along with visibility modifiers and stored member syntax.
value Declaration
A value declares an immutable, content-compared domain type. Think of it as a record or struct: two value instances are equal when all their fields are equal, regardless of where in memory they live.
Rules:
- All stored members of a
valueare immutable — you cannot usevarinside avalue. - Members must themselves be value-like types; you cannot store an
object-typed member inside avalue. - Comparison is by content, not identity.
- Construct a
valuewith the brace initialiser form:TypeName { field: expression }.
object Declaration
An object declares an identity-bearing, stateful type. Two object instances are never equal just because their fields match — each instance is a distinct entity in the program.
Rules:
- Use
varto mark mutable stored members. - Each
objecthas exactly oneinitinitialiser in v0.1. - Construct an
objectusing named arguments:TypeName(param: value). - Comparison is by identity, not content.
v0.1 allows only one
init per object. Multiple initialisers are planned for a future release.contract Declaration
A contract declares a capability promise — a named set of method and property requirements that a type can commit to fulfilling. Contracts serve the same role as interfaces in other languages.
Rules:
- A
contractdeclares requirements but never provides implementations. - Use
varin acontractto indicate a writable property requirement. - A
contractcannot declare conformance to anothercontractin v0.1. - Only
valueandobjecttypes can declare conformance.
Contract Conformance
Declare that avalue or object conforms to one or more contracts by listing them after a : following the type name, before the opening brace. Conformance is always explicit — Kairo does not infer structural conformance.
Rules:
- Separate multiple contract names with
,. - Every name in the conformance list must resolve to a
contractdeclaration. - The type must implement all requirements declared by each listed contract.
- Conformance cannot be declared elsewhere (e.g., in an extension); it belongs on the type itself.
enum Declaration
An enum declares a closed set of named cases. Use enum to represent a fixed vocabulary of distinct states or options.
Rules:
- Cases are listed one per line inside the braces; no explicit values are assigned in v0.1.
enumtypes cannot declare contract conformance in v0.1.- Reference a case as
EnumName.caseName.
Contract conformance for
enum types is planned for a future version of Kairo.Visibility Modifiers
Every declaration has a visibility level that controls where it can be accessed. Visibility is declared with a keyword before the declaration keyword (e.g.,public value, private func).
Stored Member Syntax
Members declared inside avalue or object body are stored members — they hold data for each instance.
