JuliaFunctional / ExtensibleEffects.jl

Implementing extensible effects in Julia
MIT License
12 stars 2 forks source link

trouble with type inference #10

Open cscherrer opened 2 years ago

cscherrer commented 2 years ago

Hi, in you Future Work section, you say

Julia's type-inference seems to have quite some trouble inferring through the core algorithms of ExtensibleEffects. Hence in case type-inference and speed is crucial to your effectful/monadic code, we recommend to use TypeClasses.jl as of now. The monads of TypeClasses.jl do not compose that well as the effects in ExtensibleEffects.jl, but type-inference is much simpler.

Do you see this problem across the package, or only for some types of effects? Do you have a small-ish "this really ought to work better" kind of example?

I have a couple of reasons for asking. First, I've been having some discussions with Ari Katz (I forget his username, so I'll tag him later). Ari mentioned your package and also Minijyro.jl and it seems like this approach might work well for Tilde.jl, especially given Pyro's success in this direction.

We're also both very interested in static computations, including type inference. I won't speak for Ari, but I'm no compiler expert myself - just a user who hopes the compiler can have strong support for idioms from some other languages, especially staged compilation and FP.

cscherrer commented 2 years ago

@AriMKatz

schlichtanders commented 2 years ago

Thank you @cscherrer for the interest you express. I myself haven't had that strong a motivation to pin down the reason for difficulties in type inference. I plan to have more time maintaining my packages during the next months and year, but these weeks are still very busy.

Better understanding julia's type inference is on the very top of my personal julia todo list, hence I definitely want to work on this issue. I hope that in a month I can report back some type-inference-examples.

Yes, the algorithm is recursive and hard to follow even in its simple form. Understanding the details of type-inference might be easier if you have written the code indeed.

But nevertheless, please feel invited to experiment yourself and see what infers well and what not. The algorithm is also very very much optimized for easy understanding. The easiest implementation of Eff which you will find out there I guess. If you can up with some good example which I can inspect more in detail, that might be of great help.

AriMKatz commented 2 years ago

@schlichtanders are you on the Julia zulip? We are currently having an extensive discussion about this, various use cases, how it could solve composability issues with pure IR rewriting approaches (and this be of use to many packages across the ecosystem) and how we could maybe work with the Compiler team as the embark on the new compiler /inference plugin effort to get better support for lower level tools that would enable it to be more performant