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

Unit Types

A unit type is a type that has only one single value.

In Fuzion, unit types can be used to structure an application similar to Java/C# packages as a means of encapsulation and information hiding. Also, they can be used to avoid overhead since assigning a value of a unit type is a NOP. Used as a generic argument, one can use these types to specialize code.

The unit type features sum and product are used to specialize the generic feature accum to calculate the total sum or the total product of an array of integers.

The fuzion compiler will specialize the calls to accum and produce code similar to the following. The unit type instances of sum and product disappear:

Another Application of unit types are library features. Say you have a set of trigonometry functions:

Alternatively, by making complex inherit from trigo, we can add all of its features to our namespace: