In programming, data types refer to the different kinds of values supported by a particular programming language.
Like other programming languages, Elm also has a defined set of data types.
The numeric data type represents numeric values in Elm.
Type | Function | Example |
Number | Stores numbers | 5 |
Float | Stores fractional values | The result of 5/2 i.e., 2.5 |
Integer | Stores non-fractional values | The result of 5//2 i.e., 2 |
The String data type in Elm represents a sequence of characters. They are defined within double quotes "
.
Meanwhile, the Char data type represents a single character. They are enclosed within single quotes '
.
Let’s consider the word educative
. We can represent the whole word containing nine characters with the String data type. Meanwhile, we can singly represent each of those nine characters with the Char data type.
Type | Function | example |
String | Stores multiple characters | "educative" |
Char | Stores single characters | 'e' |
The Bool data type in Elm supports the use of the values True
and False
. Boolean values are represented by the keyword Bool
.
Type | Function | Example |
Bool | Stores the values True or False | 1 == 2 returns False |
The Structured data type in Elm represents multiple or a collection of values in a structured format. The values can either be homogenous or heterogeneous.
Elm supports a variety of structured data types. They are:
Type | Function | Example |
Tuple | Stores values of different types | ("educative", 5, True, "good") |
List | Stores multiple values of the same type | myList1 = [10, 20, 30] |
Record | Stores key-value pairs | {name="educative", rating=10} |