The above is from Koka’s website and show how the inferred type can be shown to the user. Theoretically, we can do the same in Julia。 Wonder if anyone’s working on this?
It would be fun to work on.
Eg. one can add annotation on the type of functions like #' infer fn(2, 2) and when you hover over that, the function below called fn will have the inferred type shown next to the variables as above in screenshot.
Julia’s inferred types requires one to actually run the code, doesn’t it? Most other languages like python/typescript display inferred types statically without having to run the code. IMO this makes coding significantly simpler
I haven’t kept up with the developments in the vscode plugin lately
No. Just needs someone to provide a specific type for the argument and run part of the compilation process up to the point where types r inferred. Based on the post I think Cthulhu just infers the type where possible
But how does one do that without running code? Type-inference for a method happens when it is compiled, and that happens when some code is run where the method is reachable.
My impression was that the devs were unwilling to run user code by themselves to infer types
I think that Jet or Cthullu does that without running the code. You “just” look which types are returned by functions. Type inference also does not run the code, otherwise it would not be able to deal with recursive functions.
This is why to use this, the type of arguments has to be known.
I imagine a couple of factors make this more challenging. Firstly, code-generation using macros, so without macro-expansion, one doesn’t know what code one is running. Secondly, julia methods are often written to accept abstract types, so inferring the return type is difficult in general. Static type checking in python usually requires the user to add appropriate type-hints, which Julia doesn’t have.