Lesson 1 of 17

Hello, World!

Your First Gleam Program

Every Gleam program starts with imports. To print text, you need the io module from the standard library:

import gleam/io

The Entry Point

The entry point is a public function called main:

pub fn main() {
  io.println("Hello, World!")
}

The pub keyword makes the function public. The fn keyword declares a function. Gleam functions do not need explicit return types when the compiler can infer them.

Printing Output

Gleam provides two main print functions in gleam/io:

FunctionDescription
io.printlnPrints a string followed by a newline
io.printPrints a string without a newline
io.debugPrints any value in debug format and returns it

Unlike many languages, io.println only accepts strings. To print numbers or other types, you must convert them to strings first (we will learn how in later lessons).

Gleam's Design

Gleam is designed to be simple and predictable:

  • No exceptions -- errors are values, handled with the Result type.
  • No null -- optional values use the Option type.
  • Immutable data -- once a value is created, it cannot be changed.
  • Expression-based -- everything is an expression that returns a value.

Your Task

Write a program that prints exactly Hello, World! followed by a newline.

Gleam runtime loading...
Loading...
Click "Run" to execute your code.