A few months ago, Sam Tobin-Hochstadt explained to me how occurrence typing is compositional. While I had taken this for granted previously, comparing occurrence typing to other systems makes it clear that this is an important property to have.
First of all, what is occurrence typing? In dynamically typed programs, there are often type invariants enforced at program branches.
(fn [a :- (U nil String)]
(if a
(count a)