Fork me on GitHub
#cljs-dev
<
2019-11-06
>
Roman Liutikov13:11:35

@mfikes Would it make sense to propagate function return type through apply call?

mfikes13:11:56

Hrm, perhaps you can statically deduce that

Roman Liutikov13:11:31

unless target function is of multiple arities

mfikes13:11:10

Along those lines there might be a whole class of “higher order” inference algorithms

Roman Liutikov13:11:27

could you give an example?

Roman Liutikov13:11:15

@mfikes looks like return type of apply (`any`) is prioritized over return type hint, is this intentional?

Roman Liutikov13:11:36

(defn ^number f [x] x)
(apply f [1]) ;; tag here is `any`

mfikes13:11:40

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.

Roman Liutikov13:11:56

oh wait, the example is wrong

mfikes13:11:33

FWIW, on the surface, I think your apply idea is valid

Roman Liutikov13:11:24

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)

Roman Liutikov13:11:33

can’t repro in master though

Roman Liutikov13:11:21

placing the hint onto return value itself seem to fix this

mfikes13:11:49

Yeah, that would be odd. Manual hints should override inferred types

Alex Miller (Clojure team)13:11:16

Isn’t that type hint in the wrong place?

mfikes13:11:17

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

Alex Miller (Clojure team)13:11:52

Should be on the arg vector

mfikes13:11:54

Nah, Alex. ClojureScript differs on type hint placement

mfikes13:11:59

¯\(ツ)

mfikes13:11:23

I think there is a JIRA to unify with Clojure

Roman Liutikov13:11:20

@mfikes Should I file a JIRA then for higher order inference?

mfikes13:11:51

@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?

Roman Liutikov13:11:23

yeah I think it should be a good start

Roman Liutikov13:11:37

identity should be trivial as well

mfikes13:11:00

An example of a complex higher order inference might be (first (map inc [1])) being of numeric type.

mfikes13:11:41

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.

mfikes13:11:19

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)

dnolen14:11:29

we should probably start putting release notes together

mfikes14:11:25

Yeah, I'll start a PR for release notes 👍