This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-01
Channels
- # aws (37)
- # babashka (7)
- # babashka-sci-dev (2)
- # beginners (75)
- # biff (7)
- # calva (85)
- # cider (9)
- # clj-kondo (26)
- # clj-yaml (1)
- # clojure (45)
- # clojure-europe (4)
- # clojure-norway (1)
- # clojure-spec (3)
- # clojure-uk (2)
- # clojurescript (3)
- # core-typed (2)
- # cursive (12)
- # fulcro (3)
- # humbleui (5)
- # jobs (8)
- # malli (1)
- # meander (3)
- # membrane (1)
- # portal (50)
- # squint (15)
- # vim (1)
Hi everyone! I was playing with occurrence typing and something doesn't add up to me. Take the following nonsensical function:
(t/fn [x :- (t/U String Number nil)]
(if (string? x)
nil
(if (number? x)
(str x)
"nil")))
The type of this function can be easily inferred as [(t/U String Number nil) -> (t/U String nil)
. However the inferred type of t/cf
is the following:
[[(t/U Number String nil) -> (t/U String nil)
:filters {:then (& (is (t/U Number nil) 0) (! t/Str 0)),
:else (is (t/U Number String) 0)}]
{:then tt, :else ff}]
If I understand correctly, the :else
proposition tells that, if the return value of the function is a false value, then we can refine the type of x
to be (t/U Number String)
. The problem is that the only case the function returns a false value is when x
is of type String
.
Can anyone tell me what am I missing?