Is anyone working on an VSCode extension for Julia that can show the inferred types? Koka has something like this. Would be fun to work on

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.

Already works partially like VS Code Plugin for Julia now automatically shows computed type information : r/Julia (reddit.com) . Cthulhu in vscode is great : r/Julia (reddit.com)

julia.inlayHints.static.enabled is default to false that you may want to change.

5 Likes

Zentrik added this functionality last year.

There is some previous discussion about making this more automatic and user friendly at Towards Rust-level feedback on type stability.

3 Likes

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

2 Likes

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 believe you’re correct in that loading user code is not something the language server devs want to do

1 Like

Is inferring types statically in Julia more difficult than in other programming languages? If so, why?

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.