Skip to main content
Kairo provides four top-level type declaration keywords — 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 value are immutable — you cannot use var inside a value.
  • Members must themselves be value-like types; you cannot store an object-typed member inside a value.
  • Comparison is by content, not identity.
  • Construct a value with the brace initialiser form: TypeName { field: expression }.
Use value for domain concepts that are defined by their data: money amounts, addresses, coordinates, identifiers. If two instances carry the same data, they represent the same thing.

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 var to mark mutable stored members.
  • Each object has exactly one init initialiser in v0.1.
  • Construct an object using 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 contract declares requirements but never provides implementations.
  • Use var in a contract to indicate a writable property requirement.
  • A contract cannot declare conformance to another contract in v0.1.
  • Only value and object types can declare conformance.

Contract Conformance

Declare that a value 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 contract declaration.
  • 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.
If you list a contract in the conformance clause but omit a required member or method, the compiler produces a diagnostic error. There is no partial conformance.

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.
  • enum types 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).
You can omit the visibility modifier to get internal access. Being explicit with internal is fine, but it is never required.

Stored Member Syntax

Members declared inside a value or object body are stored members — they hold data for each instance.
Using var inside a value declaration is a compile-time error. All members of a value must be immutable.