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

Idiom # 4: Create a function which returns the square of an integer

See programming-idioms.org:


Using a preselected integer type:

Using a type parameter selecting a specific integer type:

Running Example

The version with type parameter can be called with different types:

We could also use a more general type constraint numeric and then call this on floats, fractions or complex numbers:

Finally, we could just leave out the type. In this case, the type is inferred from the actual arguments given in the call, u16 in this example. So this version is not type parametric and should be used only for local helper functions where the type is obvious.