Elm programs are composed of definitions and expressions. Everything in Elm is either a definition or an expression.
A constant value is defined with name = expression.
five = 5
six = 3 + 3
Functions are defined with name parameters... = expression,
parameters being only separated by space.
add number1 number2 = number1 + number2
Invoking a function also is an expression and is done by specifying its name and passing arguments for each of the function's parameters, separated by space, just like for function definition.
five = add 2 3
Parentheses can be used to specify the order of evaluation of an expression.
six = add 2 (1 * 4)
twelve = add 2 1 * 4
Elm doesn't use syntactic markers such as curly brackets, parentheses, or semicolons to specify code boundaries. It uses whitespaces and indentations instead.
-- A function split over multiple lines, so subsequent lines must be indented
add number1 number2 =
number1 + number2
https://elmprogramming.com/indentation.html
Each file in Elm is a module, and must contain a module statement before all other code.
Module names must match their file name, so module Calculator must be in file Calculator.elm.
Anything defined within a module is privately scoped to it
and cannot be accessed from outside this module, unless listed in exposing.
-- Define the Calculator module, and expose the `add` function
module Calculator exposing (add)
six = 3 + 3
add number1 number2 = number1 + number2
-- Define the Calculator module, and expose everything within: `six` and `add`
module Calculator exposing (..)
six = 3 + 3
add number1 number2 = number1 + number2
https://elm-lang.org/docs/syntax#modules
A comment is some text within the Elm file that is not interpreted as code.
It is mainly intented to be read by yourself and other programmers.
There is a lightweight syntax for single line comments, based on double dashes.
Multiline comments are also possible with the {- and -} pair
of opening and closing delimiters.
-- a single line comment
-- another single line comment
{- a multiline comment
spawning multiple lines
-}
There is a style guide, and elm-format can be used to automatically format code.