Data Types
Explore the basic data types used in Elixir, such as integers, floats, atoms, tuples, lists, maps, and binaries. Learn how these types operate within Elixir's dynamic, functional programming model to better understand data handling and structure.
Elixir is a dynamic programming language. So, we don’t declare the type of each variable. It depends on the value it holds at each moment. In this lesson, we’ll learn more about Elixir’s basic data types: integers, floats, booleans, atoms, strings, lists, and tuples. Below is the description of available data types in Elixir.
Built-in types
Elixir’s built-in types are as follows:
- Value types:
- Arbitrary-sized integers
- Floating-point numbers
- Atoms
- Ranges
- Regular expressions
- System types:
- PIDs and ports
- References
- Collection types:
- Tuples
- Lists
- Maps
- Binaries
Functions are a type too. But they have their own chapter.
Value types
The value types in Elixir represent numbers, names, ranges, and regular expressions.
Integers
Integer literals can be written as decimal (1234), hexadecimal (0xcafe), octal (0o765), and binary (0b1010). Decimal numbers may contain underscores (_). These are often used to separate groups of three digits when writing large numbers, so one million could be written 1_000_000 (or perhaps 100_0000 in China and Japan).
Floating-point numbers
Floating-point numbers are written using a decimal point. There must be at least one digit before and after the decimal point. The following are all valid floating-point literals:
1.0, 0.2456, and 0.314159e1, 314159.0e-5 ...