3.7

Value

We have used the term value without formally defining it. Mathematics defines a value as the result of a calculation. When we evaluate an expression we are performing a calculation. The terms calculation and computation can be used interchangeably. In Elm, all computations are done by evaluating expressions to yield values. This makes expressions the basic building blocks of any Elm application. No matter how complex an Elm application is, its essentially one big expression comprising of mini expressions.

So far we have only used numbers and boolean as values, but in Elm anything we can produce as a result of a computation can be considered a value. Here are some examples:

> 'c' -- character
'c'

> "pretzels" -- string
"pretzels"

> [1, 2, 3] -- list
[1,2,3]

> { a = 1, b = 2 } -- record
{ a = 1, b = 2 }

> ("first", "second") -- tuple
("first","second")

> someFunction x = x + 1 -- function
<function>

We will cover each of these values in detail later. All values in Elm can be passed as arguments to functions, returned as results, and placed in data structures.

Back to top

New chapters are coming soon!

Sign up for the Elm Programming newsletter to get notified!

* indicates required
Close