Skip to content

Standard Library Reference ​

Kettle provides a comprehensive set of built-in functions for common programming tasks, quantum computing, and system interactions.

Quick Navigation ​

CategoryDescription
Types & ConversionsType conversions, string operations, and math functions
ListsList manipulation, higher-order functions, and aggregations
Quantum OperationsQubit creation, gates, measurement, and entanglement
I/O & EnvironmentFile 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:

NotationMeaning
TGeneric 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) -> BFunction 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 fn

See Quantum Operations for details on the Quantum effect.