Quantum Computing with Sounio
Sounio enforces the no-cloning theorem of quantum mechanics at compile time via linear types: a Qubit is a linear resource that must be consumed exactly once. Attempting to copy it produces a compile error.
Linear Types for Quantum States
// A Qubit cannot be cloned.
// standard quantum gates (H, X, Y, Z, CNOT) consume and return Qubits.
fn apply_hadamard(q: Qubit) -> Qubit {
// apply H gate ...
}
struct QubitPair { fst: Qubit, snd: Qubit }
fn apply_cnot_pair(control: Qubit, target: Qubit) -> QubitPair {
// apply CNOT gate ...
}
fn bell_state() -> QubitPair {
let q1 = allocate_qubit()
let q2 = allocate_qubit()
let h1 = apply_hadamard(q1)
let pair = apply_cnot_pair(h1, q2)
pair
}