Hello World in PureScript

Our first program will print the classic “hello world” message. Here’s the full source code.

module Main where

import Prelude
import Effect.Console (log)

main :: Effect Unit
main = log "hello world"

To run the program, save the code in hello-world.purs and use spago to build and run it.

$ spago run
hello world

Sometimes we’ll want to build our programs into a JavaScript file that can be executed directly with Node.js.

First, compile the code into JavaScript:

$ spago bundle-app --main Main --to hello-world.js

We can then execute the bundled JavaScript file directly using Node.js.

$ node hello-world.js
hello world

Now that we can run and build basic programs, let’s learn more about the language.