Part three of a small series explaining Fuzion using idioms from programming-idioms.org/.
Fuzion idiom #3, Create a procedure:
A procedure in Fuzion is a feature with effects.
A small 🧵1/8…

The feature declared here is called `finish`. It has one argument `name` of type `String`. The arrow `=>` says that this feature is a function and the result type is inferred automatically from the code.
…2/8…

Follow

To call this feature, it is sufficient to write the name followed by an argument of type `String`, here we call `finish "schöne Welt!"`:
…3/8…

The code of `finish` performs a call to `say`, which prints a given string and returns a value of type `unit`, which in Fuzion has a similar role like `void` in Java or C, but it is a proper first-class type. So the inferred result type of `finish` is `unit` as well.
…4/8…

Fuzion uses effects, which means that `say` does not just print the string, but it uses the `io.out` effect from the current environment. The default `io.out` prints that string to `stdout`, but we could replace it by an effect that does something else.
…5/8…

The effects that are required by a feature can be determined by static analysis. Analysing our example for effects (by selecting `Effects!`) results in `io.out`:
…6/8…

For library features, the effects must be explicit. In our example, if we would want to place it in a library, we must hence add `! io.out` after the type signature to document the use of this effect, otherwise building that library module would result in an error:
…7/8…

More on the Fuzion language, more examples, idioms, a tutorial, design background can be found at flang.dev
…8/8.

Sign in to participate in the conversation
types.pl

A Mastodon instance for programming language theorists and mathematicians. Or just anyone who wants to hang out.