microsoft / qsharp-language

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

Make custom inline arithmetic operators possible #144

Open Strilanc opened 5 years ago

Strilanc commented 5 years ago

A major source of boilerplate and typos and readability issues in my Q# programs is having to write things like this:

PlusEqual(target, offset)

Instead of this:

target += offset

Or this:

PlusEqualQuantumClassicalProductLE(a, b, 53)

instead of this:

a += b * 53

I would find it very useful if there were some mechanism to fix that. There are many possible ways to do so. For example, a pattern matching system:

match (a: LittleEndian, b: LittleEndian, c: BigInt)
    in (a += b * c)
    to PlusEqualQuantumClassicalProductLE(a, b, c);
match (a: LittleEndian, b: LittleEndian, c: BigInt)
    in (a += c * b)
    to PlusEqualQuantumClassicalProductLE(a, b, c);
match (a: LittleEndian, b: LittleEndian, c: BigInt)
    in (a -= b * c)
    to Adjoint PlusEqualQuantumClassicalProductLE(a, b, c);
match (a: LittleEndian, b: LittleEndian, c: BigInt)
    in (a -= c * b)
    to Adjoint PlusEqualQuantumClassicalProductLE(a, b, c);
cpalmer2020 commented 5 years ago

Thanks. We'll look into this.

bettinaheim commented 5 years ago

Thank you for your input! We are considering providing support for (de-facto) operator overloading in the future. Such a support could potentially be achieved via the infrastructure needed for other language features we are considering - e.g. type specializations. A patten matching mechanism is certainly interesting to look into as well. In any case, it will likely take some time before we can potentially support this, since we would rather address this in a uniform way as part of a larger extension to the Q# language.

bettinaheim commented 5 years ago

Note that changes to the Q# language are subject to our language design process. At this point we are not ready for contributions implementing this feature yet. This issue will migrate to the appropriate repository in the near future and will be processed there.

alan-geller commented 2 years ago

I'm going to transfer this issue to the qsharp-language repo, since that's now the proper place for language suggestions.