A Tour of Morfa

Hello world!

Let us put our example Morfa programs in a directory called tutorial:

$ mkdir tutorial
$ <edit> tutorial/hello.morfa

Obviously, <edit> is a placeholder for your favourite text editor.

Here is the standard Hello World! in Morfa:

module tutorial.hello;
import morfa.io.print: printf;

func main()
{
    greet("World");
}

func greet(who: text)
{
    var hello = "Hello";
    printf("{} {}!\n", hello, who);
}

We made this example more complex that is should be, just to show some extra Morfa code.

The first line is the module declaration and tutorial.hello is the name of the module (each source file contains exactly one Morfa module). In the second line we tell the compiler to also read the library module morfa.io.print, from which we will need the function println.

As you probably guessed, main is the function from which the execution starts. Inside main's body we call another function called greet with the text "World" as the argument.

Inside greet we declare a variable hello and use it, together with the parameter who to print a greeting message.

You can run your first program using the morfai command

$ morfai -run tutorial/hello.morfa
Hello World!