The treat as operator fools the static type checker.
Suppose, for example, that you have a function that operates on UK addresses. If the static type of $curAddr isn’t a UK address, you can still pass it to the function as follows:
$curAddr treat as element(*, eg:UKAddress)
A dynamic error will occur if the address isn’t a UK address.