In https://github.com/clojure/core.typed/wiki/User-Guide#occurrence-typing an example of occurrence typing is provided:
clojure.core.typed=> (cf (let [a (ann-form 1 Any)]
(cond
(symbol? a) a
(number? a) a)))
(U Sym Num nil)
Why exactly is (ann-form 1 Any) used? I guess it is a hacky/idiomatic way to set the type of a by annotating 1 and then setting a to that value, but I can't really understand why this is chosen syntax for doing this.
ann-formjust forgets type information about a particular expression.Here we forget
1is a(Val 1), and consider it of typeAnyfor the rest of the program. This way we can demonstrate how occurrence typing works with local bindings of typeAny.You can also write it with clojure.core.typed/let like so: