Skip to content

Introduction to Kettle ​

Kettle is a functional programming language designed for quantum-classical hybrid computing. It combines:

  • Static typing with type inference
  • Linear types that prevent quantum state cloning
  • Effect tracking that makes side effects explicit
  • Capabilities like Reversible for automatic uncomputation
  • Pattern matching and pipelines for elegant code

Quick Example ​

Here's a taste of what Kettle code looks like:

kettle
-- Define a custom type
type Point = record
  x: Float
  y: Float
end record

-- Calculate distance between two points
fn distance(p1: Point, p2: Point) -> Float
  dx = p2.x - p1.x
  dy = p2.y - p1.y
  sqrt(dx * dx + dy * dy)
end fn

-- A quantum function with effects
fn bell_pair() -> Tuple[Int, Int] with Quantum
  (a, b) = bell()
  (measure(a), measure(b))
end fn

fn main() -> Unit using file_io
  origin = Point { x: 0.0, y: 0.0 }
  target = Point { x: 3.0, y: 4.0 }

  result = distance(origin, target)
  print("Distance: ${to_stringf(result)}")

  -- Pattern matching
  match result > 0.0
    True -> print("Valid distance")
    False -> print("Invalid")
  end match
end fn

Functional Pipelines ​

Kettle embraces functional programming with pipes and higher-order functions:

kettle
fn main() -> Unit using file_io
  numbers = [1, 2, 3, 4, 5]

  -- Pipeline: filter evens, multiply by 10, sum
  evens = numbers | filter(fn(x: Int) -> x % 2 == 0)
  doubled = evens | map(fn(x: Int) -> x * 10)
  result = doubled | fold(0, fn(acc: Int, x: Int) -> acc + x)

  print("Sum of doubled evens: ${to_string(result)}")
end fn

Quantum Computing ​

Linear types ensure qubits are used correctly, and effects track quantum operations:

kettle
-- Quantum function creates superposition and measures
fn coin_flip() -> Int with Quantum
  q = qubit()
  q <- hadamard   -- put in superposition
  measure(q)      -- collapse to 0 or 1
end fn

fn main() -> Unit using quantum_simulator(shots = 10), file_io
  results = coin_flip()  -- returns list of 10 results
  print("Quantum coin flips:")
  print(results)
end fn

Entanglement ​

Multi-qubit operations create quantum correlations:

kettle
fn bell_state() -> Tuple[Int, Int] with Quantum
  q1 = qubit()
  q2 = qubit()
  q1 <- hadamard    -- superposition
  q1, q2 <- cnot    -- entangle
  (measure(q1), measure(q2))  -- always same!
end fn

Next Steps ​