Skip to main content

Hello, Fino!

info

This tutorial aims to be beginner-friendly to people new to Fino, or new to the functional programming paradigm. It assumes some prior programming experience.

Now that we've hopefully installed Fino correctly, it's time to test out the language - with the classic Hello, Fino! program of course.

In this short section, we will:

  • Write a simple program which prints a message
  • Extend it to take in user input
  • Dip our toes in a few simple but powerful features of the language
  • Get an idea of how it feels to write effectful code in Fino

Writing the code

Get started by creating a new file, call it whatever you want, and preferably give it a .fn file extension. Open up the file in your favourite text editor and proceed by writing the following lines of code:

hello-world.fn
import prelude

fn main : unit -> unit
() = println "Hello, Fino!"

Click on a tab to understand what a specific line of code does:

This line imports the prelude module from the standard library, which in turn brings a small set of essential modules into scope, such as the io module which we use println from (on line 4).

Running the program

As described in the previous section on usage, to compile the program use the following command:

fino -f hello-world.fn -o hello-world.bin

And then simply run the executable to run the program:

./hello-world.bin

You should see the following output:

Hello, Fino!

Some more

While writing a Hello, Fino! program is fun, let's try exploring some more of the language. Specifically, let's extend our program to take in user input in the form of a name, and then output a greeting.

As before, create a new file, name it whatever you want, and give it a .fn file extension. Edit the file and write the following few lines of code:

greeting.fn
import prelude

fn main : unit -> unit
() = do
println "What is your name?"
let name = input ()
println ("Hello, " + name + "!")
note

Currently, do notation (and consequently mdo) is only a planned feature and is not implemented in the compiler yet. To actually have a working program, look at the code below.

Now we've introduced a few more language features: do notation, let bindings, and user-defined operators.

[WIP]

Without do notation

Here is the same function written without do notation

greeting.fn
import prelude

fn main : unit -> unit
() =
let _ = println "What is your name?" in
let name = input () in
println ("Hello, " + name + "!")

An exercise