The cast as operator coerces the type of an item.
$x cast as eg:HatSize
returns the value of $x as an item of type eg:HatSize.