Skip to main content
The classic Hello World program is the perfect starting point for learning Elara. This example demonstrates the basic structure of an Elara program and how to perform simple output.
1

Basic Hello World

The simplest Elara program that prints output:
def main : IO ()
let main = print "Hello, World!"
What this does:
  • def main : IO () declares the type signature for main as an IO action that returns unit (nothing)
  • let main = print "Hello, World!" defines the main function that prints the string
  • The print function comes from the standard library and outputs text
Expected Output:
Hello, World!
Every Elara program must have a main function of type IO () as the entry point.
2

Using println

You can also use println to automatically add a newline:
import Prelude
import Elara.Prim

def main : IO ()
let main = println "Hello, World!"
Expected Output:
Hello, World!

println is preferred over print in most cases as it adds a newline character automatically.
3

String Concatenation

You can build more complex strings using the ++ operator:
import Prelude
import Elara.Prim
import String

def main : IO ()
let main =
    let name = "Elara"
    let version = "0.1"
    println ("Welcome to " ++ name ++ " v" ++ version ++ "!")
Expected Output:
Welcome to Elara v0.1!
Key Concepts:
  • The ++ operator concatenates strings
  • Local bindings use let expressions
  • The String module provides string utilities
4

Working with Numbers

Converting numbers to strings for display:
import Prelude
import Elara.Prim
import String

def main : IO ()
let main =
    let answer = 42
    println ("The answer is: " ++ toString answer)
Expected Output:
The answer is: 42
Key Concepts:
  • toString converts integers to strings for concatenation
  • Numeric literals are inferred as Int by default

Next Steps

Now that you understand the basics, explore more advanced examples:

Build docs developers (and LLMs) love