Every type a program can use without use: numbers, text, collections, errors, tasks and channels, shared state, and the interfaces the language relies on. Each with what it is and where it is defined.
These need no use. Their methods are listed in Built-in Methods, and the types a module adds on its module's page. Each type links to the course page that teaches it with examples that run.
Numbers, text and values
| Type | What it is | Learn · defined in |
|---|
Int
| 64-bit signed integer | |
Int8
Int16
Int32
UInt8
UInt16
UInt32
UInt64
| Sized integers | |
Float
| 64-bit floating point | |
Float32
| 32-bit floating point: rounded to single precision at every step, and printed as the shortest text that reads back as the same Float32 (0.1). What GPUs compute fastest (chapter 15) | |
Decimal
| Exact base-10 number, with as many digits as it needs. Use it for money | |
BigInt
| A whole number of any size. Slower than Int: use it when values may not fit in 64 bits | |
Bool
| true or false | |
Char
| One Unicode character | |
String
| Immutable UTF-8 text | |
Bytes
| Immutable raw bytes | |
Json
| A JSON value whose shape is known only when the program runs (2.12) | |
| Type | What it is | Learn · defined in |
|---|
List
| Written [T]; a literal: [1, 2, 3] | |
Map
| Written [K: V]; a literal: ["asha": 31, "ravi": 27], empty: [:] | |
Set
| Written Set<T>; a literal: Set.of(1, 2, 3) | |
| Type | What it is | Learn · defined in |
|---|
Error
| For scripts and application code that just wants to stop on any error, ! Error accepts every error type | |
ParseError
| It can fail with a ParseError, so it takes try or catch. Int("23sd") fails, as does Int("300") into Int8. | |
JsonError
| Why JSON text could not be read (spec 2.12). | |
Tasks and channels
| Type | What it is | Learn · defined in |
|---|
Task
| spawn starts a task and returns a Task<T>. .wait() gets its result. | |
Channel
Sender
Receiver
| Channels pass values between tasks. Channel<T>(capacity: n) gives its two ends, a Sender<T> and a Receiver<T> | |
Taken
| What receive.take() gives: the next value, or Closed once the channel is closed and empty. A none sent on a Channel<T?> is Item(value: none), never Closed (decision 0097). | |
Shared state and memory
| Type | What it is | Learn · defined in |
|---|
Shared
| Shared<T> is the only way to get shared, mutable state. | |
Weak
| Weak<T> points to a Shared<T> without keeping it alive. | |
Ptr
| A Ptr<T> is the address of T values in memory Kavach doesn't manage, as C has it. | |
Files, text and networks
| Type | What it is | Learn · defined in |
|---|
Lines
Chunks
| fs.lines gives a reader of type Lines and fs.chunks one of type Chunks | |
Regex
RegexError
| regex.new(pattern) -> Regex ! RegexError: A pattern for the linear-time engine: matching takes time proportional to the text, whatever the pattern and the text. Safe for patterns and text from users | |
CliError
| cli.parse<T>() -> T ! CliError: The arguments, parsed into record type T, or into union type T of commands. Needs Env | |
Listener
| net.listen(address) -> Listener ! NetError: Listens for connections at address | |
Connection
| net.connect(address) -> Connection ! NetError: A connection to address | |
UdpSocket
| net.bind(address) -> UdpSocket ! NetError: A UDP socket at address | |
| Type | What it is | Learn · defined in |
|---|
Display
| A type can choose its own form by implementing the Display interface (fn display(self) -> String). | |
Drop
| Types that hold resources can run cleanup by implementing Drop | |
Comparable
| <T: Comparable> means "any type T that implements the interface Comparable". | |