Skip to content

Types

Type Description Example
Int 64-bit signed integer 42
Float 64-bit floating point 3.14
Bool Boolean true, false
String UTF-8 string "hello"
Char Single Unicode character 'z'
Void No value (unit type)

Ordered, homogeneous collections:

let numbers: List[Int] = [1, 2, 3, 4, 5]
let names = ["Alice", "Bob", "Charlie"] // inferred as List[String]
print(numbers[0]) // 1
print(names.len()) // 3

Key-value associations:

let ages: Map[String, Int] = {
"Alice": 30,
"Bob": 25,
}
print(ages["Alice"]) // 30

Fixed-size, heterogeneous groupings:

let point: (Int, Int) = (10, 20)
let (x, y) = point // destructuring

Named product types with fields:

struct User {
name: String,
email: String,
age: Int,
}
let user = User {
name: "Alice",
email: "alice@example.com",
age: 30,
}

Sum types (tagged unions):

enum Shape {
Circle(Float),
Rectangle(Float, Float),
Triangle(Float, Float, Float),
}
let s = Shape.Circle(5.0)

Zap has no null. Instead, use built-in types:

// Option — a value that might not exist
let found: Option[User] = find_user("alice")
match found {
Some(user) => print(user.name),
None => print("Not found"),
}
// Result — an operation that might fail
let data: Result[String, Error] = read_file("config.toml")
match data {
Ok(content) => print(content),
Err(e) => print("Error: " + e.message),
}

Functions and types can be parameterised:

fn first[T](list: List[T]) -> Option[T] {
if list.len() > 0 {
Some(list[0])
} else {
None
}
}
type UserId = Int
type UserMap = Map[UserId, User]

Learn about functions and how to use types in practice.