This page is available as PDF here.
Variables and Types
Epos is statically typed with type inference, making it both safe and expressive.
Variable Declaration
Variables in Epos are immutable:
name: string = "Alice"
age: int = 25
height: float = 5.8
-active: bool = true is
You can also use type inference:
= "Alice" # inferred as string
name := 25 # inferred as int
age := 5.8 # inferred as float
height :-active := true # inferred as bool is
Built-in Types
Primitive Types
int
: Integer numbersfloat
: Floating-point numbersstring
: Text stringsbool
: Boolean values (true/false)
String Interpolation
Embed expressions in strings using #{}
:
= "World"
name :message: string = "Hello #{name}!"
= 42
count :status: string = "There are #{count} items"
Lists
Lists are homogeneous collections:
numbers: list(int) = {1, 2, 3, 4, 5}
names: list(string) = {"Alice", "Bob", "Charlie"}
flags: list(bool) = {true, false, true}
# Nested lists
matrix: list(list(int)) = {{1, 2}, {3, 4}, {5, 6}}
Ranges are also supported:
range: list(int) = 1..10 # 1, 2, 3, ..., 10
Get the length of a list using len()
:
({1, 2, 3}) # => 3 len
Access list elements using elem()
:
first: int = elem(numbers, 0) # Gets first element
last: int = numbers.elem(len(numbers) - 1) # Gets last element
Records
Records are structured data types:
Person
record name: string
age: int
email?: string # Optional field
end
person: Person = @{
=> "Alice",
name => 30,
age => "alice@example.com"
email }
# Access record fields
(person.name) # Dot notation
print(person["age"]) # Bracket notation print
Type Aliases
Create aliases for complex types:
UserId = int
type EmailAddress = string
type UserList = list(Person)
type
-id: UserId = 123
useremails: list(EmailAddress) = {"alice@example.com", "bob@example.com"}
Union Types
Union types allow you to combine different types:
UserId = int | string
type
-id: UserId = 123
user-id: UserId = "alice@example.com" user
Generics
Epos supports generic types for reusable code:
# Generic function that works with any type
fn identity(value: t): t
valueend
# Generic record
Pair(a, b)
record first: a
second: b
end
coord: Pair(int, int) = @{
=> 10,
first => 20
second }
Visibility
By default, everything is private. Use “*” for public declarations:
-key: string = "abc123" # Private variable
secret*: string = "public-name" # Public variable
name
fn internal-helper(): int
42
end
fn public-function*(): int
-helper()
internalend
Next, learn about functions in Epos.
Next page →