microsoft / qsharp-language

Official repository for design of the quantum programming language Q# and its core libraries
MIT License
233 stars 54 forks source link

Allow qubit in `if` expression, meaning "use this as a control for all operations in the block" #130

Open Strilanc opened 2 years ago

Strilanc commented 2 years ago

Add sugar to the language so that this:

if qubit {
    swap(a, b);
    other_thing(b, c);
}

becomes this:

Controlled swap([qubit], (a, b));
Controlled other_thing([qubit], (b, c));

If the sugar produces bad results (e.g. attempting to control an operation that has no controlled variant), that's a compile error.

Note that if b { f(c, d); } is fewer characters than Controlled f([b], (c, d)), is easier to type, and IMO is easier to read.