Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Conditional expressions consist of three sub-expressions, where the left-most sub-expression is of type Bool and determines which one of the two other sub-expressions is evaluated. They are of the form
cond ? ifTrue | ifFalse
Specifically, if cond evaluates to true, then the conditional expression evaluates to the ifTrue expression; otherwise, it evaluates to the ifFalse expression. The other expression (the ifFalse and ifTrue expression, respectively) is never evaluated, much like the branches in an if statement.
For instance, in an expression a == b ? C(qs) | D(qs), if a equals b, then the callable C is invoked. Otherwise, D is invoked.
The types of the ifTrue and the ifFalse expression have to have a common base type. Independent of which one ultimately yields the value to which the expression evaluates, its type always matches the determined base type.
For example, if
Op1is of typeQubit[] => Unit is AdjOp2is of typeQubit[] => Unit is CtlOp3is of typeQubit[] => Unit is Adj + Ctl
then
cond ? Op1 | Op2is of typeQubit[] => Unitcond ? Op1 | Op3is of typeQubit[] => Unit is Adjcond ? Op2 | Op3is of typeQubit[] => Unit is Ctl
For more details, see subtyping.