@mfikes Would it make sense to propagate function return type through apply
call?
Hrm, perhaps you can statically deduce that
unless target function is of multiple arities
Along those lines there might be a whole class of “higher order” inference algorithms
could you give an example?
identity
alright 🙂
@mfikes looks like return type of apply
(`any`) is prioritized over return type hint, is this intentional?
(defn ^number f [x] x)
(apply f [1]) ;; tag here is `any`
That’s a trivial example, but there are probably semi-complicated higher order cases where, as a human you can statically deduce types where the compiler is not yet doing so.
oh wait, the example is wrong
FWIW, on the surface, I think your apply
idea is valid
hm, this is a different question, but I’m hitting a weird case where return type of fx
is any
even though there’s return type hint
(defn f [x] x)
(defn ^number fx []
(apply f [1]))
(fx)
can’t repro in master though
placing the hint onto return value itself seem to fix this
Yeah, that would be odd. Manual hints should override inferred types
Isn’t that type hint in the wrong place?
I think with apply
you’d need to be careful in the multi-arity case to ensure that, you get the union of all return types
Should be on the arg vector
Nah, Alex. ClojureScript differs on type hint placement
¯\(ツ)/¯
Ah, sorry
I think there is a JIRA to unify with Clojure
@mfikes Should I file a JIRA then for higher order inference?
@roman01la Off the top of my head, I don’t know of any general algorithm. Maybe it makes sense to do specific things like apply
, and see if any generaliztion falls out of those kinds of things?
yeah I think it should be a good start
identity
should be trivial as well
An example of a complex higher order inference might be (first (map inc [1]))
being of numeric type.
As a human, you can easily see this is the case, but the compiler is far away from being able to handle stuff like that.
I suspect, that even if we managed to do higher order inference, the first baby steps would likely heavily rely on static knowledge of the semantics of core functions (as opposed to being able to do similar inference for user-defined functions)
we should probably start putting release notes together
Yeah, I'll start a PR for release notes 👍