Example 3

Given Input Type XQuery Expression Expected Output Type
<!ELEMENT r (b,c,b*)>
<!ELEMENT b EMPTY>
<!ELEMENT c EMPTY>
        <r>{for $x in child::* return $x}</r>  
        
<!ELEMENT r (b+,c,b*)>
<!ELEMENT b EMPTY>
<!ELEMENT c EMPTY>

Explanation

An example discussed in the paper by D. Colazzo and C. Sartiani (PPDP'11). We can observe in this case that backward type inference completely overcomes the precision problems met in approaches based on forward type inference. This is because backward type inference may simply copy portions of the output type into the inferred input type. This is a great advantage in terms of complexity since it avoids an exponential case analysis, and only uses a linear copy instead.

Full Trace

The full trace generated by the implementation for the example above: