#Quick Start

The fastest way to follow along is the playground, which runs every example in this guide in your browser. To work locally instead, put a program in a file ending in .mdk and run it with the medaka binary (build it from source by following the Install section of the README):

medaka run hello.mdk

That type-checks the program and runs it in one step.

#Hello, world

A Medaka program starts at main.

main = println "Hello world!"

Running it prints:

Hello world!

main is a value, not a function. You define it with main = … and never with parameters. When you run the program, main is evaluated for its effects, in this case printing a line. If main is a plain value instead, such as main = 2 + 5, running the program prints that value, here 7.

⚠️ Write main = …, not main () = …. A main with a parameter is a function that nothing ever calls. The compiler warns about it under medaka check, and medaka run and medaka build refuse to go ahead:

error: hello.mdk:1:10: 'main' must be a value, not a function. Write 'main = …',
not 'main () = …' or 'main x = …': a program starts by evaluating 'main', and
nothing ever calls it

#Doing several things

To do more than one thing, put the statements on separate lines, indented under main. They run top to bottom.

main =
  println "What's in the box?"
  println "A fish."
What's in the box?
A fish.

That is all there is to sequencing in Medaka. There is no special keyword for a block of statements and no wrapper type around IO. Chapter 7 explains how the compiler still keeps track of which functions do IO.

⚠️ Indentation is the syntax. Medaka has no braces and no semicolons. The two println lines above form a block because they are indented under main by the same amount. When the indentation is wrong, the error is often not about indentation: a statement indented one space too far or too little is frequently reported as Unbound variable, because the compiler closed the block before it reached your line. If a name you can plainly see is reported as unbound, check the columns first.

#Comments

A line comment starts with -- and runs to the end of the line. A block comment is written between {- and -}, and block comments nest, so you can comment out a region that already contains one.

-- A line comment.
main = println (2 + 5)  -- A comment can also follow code.
7
{- A block comment.
   It can span several lines, and {- it nests -} cleanly. -}
main = println (2 + 5)
7

Next: values, bindings, and types, which is what goes on the right-hand side of those statements.