Skip to content

Fixed-size value types

A property groups cell state that behaviors can require and models compose. A struct is an ordinary value: use it inside properties, inputs, constants, function arguments and results. It has no methods, inheritance or identity.

main.hyle
type Vector = [Float; 3];
struct Motion { velocity: Vector; }
enum State { Moving, Stopped }
const dt: Float = 0.5;
fn accelerate(value: Motion) -> Motion {
Motion {
velocity: [value.velocity[0], value.velocity[1], value.velocity[2] - dt],
}
}
property Body {
motion: Motion = Motion { velocity: [0.0; 3] };
state: State = State::Moving;
}
model Particle: Body;
world { dimensions = 3; }
behavior Advance for Body {
update when self.state == State::Moving {
set self.motion = accelerate(self.motion);
set self.state = State::Stopped;
}
}
phase advance { run Advance on Particle; }

This particle accelerates once, then its enum state disables the update. All declarations can be forward-referenced. Keep world and phases in main.hyle; value declarations may live in any project .hyle file.

  • Motion { velocity: [0.0, 0.0, 1.0] } supplies every named struct field. Constructor field order is free. Missing, extra or duplicate fields are errors.
  • [Float; 3] is a homogeneous, fixed-size array. [0.0; 3] repeats a value. Lengths in type declarations and repeat counts can use named Int constants. For example, const COUNT: Int = 3; type Samples = [Float; COUNT];.
  • self.motion.velocity[2] reads one component. A set may replace a whole value, a nested field or an array element. Reads still use the phase’s committed state.
  • State::Moving is a nominal enum value. Only == and != with the same enum are supported; variants have no payloads and cannot be assigned numeric ordinals.
  • type Vector = [Float; 3]; is a transparent alias. It adds a readable name without creating an incompatible type. Two separately declared structs or enums are distinct.

Write 0.0 for Float elements. Functions and compound values keep exact type contracts; an array of Ints is not an array of Floats. No implicit array broadcasting, vector arithmetic or whole-record comparison is provided. Write the needed math in small pure functions.

Every property field used by a model needs an initial value: provide it on the property, in a named preset, or in the model’s inline block. This applies to scalar and compound fields alike. Struct declarations describe a shape; they do not supply defaults for a property of that type.

Inputs are different: omitting their initializer gives zero/false, recursively for arrays and records; an enum input defaults to its first declared variant. Explicit initializers are recommended when zero is not a meaningful starting value. Scalar aliases accept inclusive bounds, such as temperature: Temperature [0.0, 1.0] = 0.25;. Intervals do not apply to an entire compound value. Clamp individual values in physics when needed.

The same types, constants and pure functions are available to .hyleworld:

place Particle at [0, 0, 0] {
set target.motion = Motion { velocity: [0.0, 0.0, 2.0] };
set target.state = State::Moving;
}

World functions may also accept and return these values. Legends can initialize compound fields. Geometry files remain independent of their material types. Forking a captured state reconstructs valid member assignments and enum names.

Published reusable parts carry their type definitions and pure context. They still use exact revision imports. Conflicting type definitions are rejected; types are not separate registry artifact kinds in this first implementation.

Layouts are fixed: no recursive types, dynamic arrays, slices, references, methods, enum payloads or heap allocation. Each array has 1–4096 elements and each value has at most 4096 scalar components. Recursive helper calls and excessive expansion are compile errors.

Array reads and writes accept computed Int indices in physics, visuals, pure helpers and world construction. For example, set self.samples[selected] = 0.5;. Every index is checked before access. Negative indices and indices at or above the array length reject the current step; the previous completed step remains intact, including when earlier phases had already computed results. Construction failures reject the world build. Constant invalid indices remain compile errors.

No range proofs or additional range annotations are required. Existing declared field and input bounds still apply. Struct and enum metadata is retained in compiled output; changed type contracts remain distinguishable in saved modules.

CPU-32, CPU-64 and GPU-32 support Float, Int, Bool and plain enums, including inside structs and arrays. Native GPU-64 uses the same discrete representation but requires compatible hardware. Float precision remains a solver setting; Int arithmetic is checked signed 64-bit arithmetic on every solver. Integer overflow rejects the step. Mixed Int/Float operations convert to the selected Float precision and may round.

Studio exposes enum inputs as named choices and compound inputs as individually editable fields. Enums remain values rather than quantities: streaming applies to numeric fields, not enum variants or Booleans.

Hyle Astro