Standard Library Reference ​
Kettle provides a comprehensive set of built-in functions for common programming tasks, quantum computing, and system interactions.
Quick Navigation ​
| Category | Description |
|---|---|
| Types & Conversions | Type conversions, string operations, and math functions |
| Lists | List manipulation, higher-order functions, and aggregations |
| Quantum Operations | Qubit creation, gates, measurement, and entanglement |
| I/O & Environment | File operations and environment access |
Function Categories ​
Types & Conversions ​
Core functions for working with basic types:
- Output:
print- Display values - Conversions:
to_string,to_float,to_int,parse_float - Strings:
split,join,trim,substring,replace, and more - Math:
abs,sqrt,sin,cos,pow,floor,ceil
Lists ​
Functional list operations:
- Access:
head,tail,last,get_at - Transform:
map,filter,fold,reverse - Combine:
append,concat,take,drop - Aggregate:
sum,mean,counts,most_common
Quantum Operations ​
All quantum functions require the Quantum effect:
- Creation:
qubit,qubits,bell - Single-Qubit Gates:
hadamard,pauli_x,pauli_y,pauli_z,rx,ry,rz - Multi-Qubit Gates:
cnot,cz,swap,ccnot - Measurement:
measure,measure_all
I/O & Environment ​
System interaction functions:
- Files:
read_file,write_file,file_exists - Environment:
get_env
Type Notation ​
Throughout this reference, we use the following type notation:
| Notation | Meaning |
|---|---|
T | Generic type parameter |
List[T] | List containing elements of type T |
Option[T] | Optional value (Some or None) |
Result[T, E] | Result type (Ok or Err) |
Tuple[A, B] | Tuple of two values |
fn(A) -> B | Function from A to B |
Effects ​
Some functions require specific effects to be declared:
kettle
-- Quantum operations require `with Quantum`
fn quantum_example() -> Int with Quantum
q = qubit()
q <- hadamard
measure(q)
end fn
-- IO operations require `using` a handler
fn main() -> Unit using quantum_simulator, file_io
print(quantum_example())
end fnSee Quantum Operations for details on the Quantum effect.