3 ms·
Typed Racket actually has a rather marvelous type system. The following is fine therein and statically type checks: (let ([x (if (condition) "string" (lis
by Blikkentrekker 5y ago
Typed Racket actually has a rather marvelous type system.
The following is fine therein and statically type checks:
(let ([x (if (condition) "string" (list "a list"))])
(if (string? x)
(string-length? x)
(length? x)))
By process of elimination, because the type of the variable is `(U string? (List-of string?))`, the type checker can prove that if `(string? x)~ be false, the type of `x` must be `list?`, and that `(length x)` succeeds.