This is what hello world looks like in elixir:

defmodule HelloWorld do
  @doc """
  Simply returns "Hello, World!"
  """
  @spec hello :: String.t()
  def hello do
    "Hello, World!"
  end
end

Note: Elixir allows writing docs + tests alongside functions, which can be parsed out into unit tests. Cool!

Elixir functions can also be shortened to nifty oneliners, ditching the end like so:

def hello(), do: "Hello, World!"
end of storey Last modified: