Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

Type unit

The most fundamental types in Fuzion are unit and void

A unit type is a type that has only one possible value. Passing a value of unit type to a function or assigning it to a field does not pass any actual information around.

The unit type hence plays a role similar to type void in Java or C++ code. A difference is that the value of unit type can be produced explicitly by calling its constructor unit. The following example uses this to explicitly return an instance of type unit by feature print3times:

If we do not return unit explicitly, the result is that of the last call to say, which happens to be unit:

In case the last statement in a feature with result type unit does not result in a unit value, we get an error:

The result of an empty block is unit, so we can return {} explicitly:

or have unit as the implicit result of an empty feature: