In the case when we have swaps, type expansion needs to take account of these swaps, or else the ordering of the wires will be wrong.
For instance, consider "Bob who Alice loves runs". This should be semantically equivalent to "Alice loves Bob" and "Bob runs".
After pulling out we get the following diagram
With our current code, if we now apply n type expansion and then type expand (s type expansion) to the above, we get the following incorrect diagram, which puts "runs" onto the wire that now corresponds to "Alice"
In the case when we have swaps, type expansion needs to take account of these swaps, or else the ordering of the wires will be wrong.
For instance, consider "Bob who Alice loves runs". This should be semantically equivalent to "Alice loves Bob" and "Bob runs". After pulling out we get the following diagram
With our current code, if we now apply n type expansion and then type expand (s type expansion) to the above, we get the following incorrect diagram, which puts "runs" onto the wire that now corresponds to "Alice"