r/ProgrammingLanguages • u/marvinborner bruijn, effekt • Apr 27 '26
Discussion Effekt: Name-Based Implicits
https://effekt-lang.org/tour/name-based-implicitsWe recently added name-based implicits to our language. It's based on the work by Daan Leijen and Tim Whiting "Syntactic Implicit Parameters with Static Overloading". Let us know of your thoughts!
29
Upvotes
5
u/thunderseethe Apr 27 '26
How does this interact with polymorphism? If I have both a
compare: (A, A) => Orderingand acompare: (Int, Int) => Ordering, which one does mySort2 select when its instantiated atInt?4
u/RndmPrsn11 Apr 27 '26
Nice! Always love following along with Effekt's progress. I've had implicits in my language Ante for some time now and use them as the basis for traits and am currently reworking effects into capabilities passed via implicits as well. I will say, I am more hesitant on name-based implicits rather than type-based ones.
I tend to think of names as not mattering to the language itself, which allows users the added flexibility to be more descriptive and disambiguate similar names. In the ambiguous implicits error you posted below for example, the compiler must mention each duplicate name but it may be clearer to users if the implicits system allowed the names to be different such that the error could instead read (e.g.) "There are multiple overloads, which all would type check: `int_ord`, `any_ord`"
I also think it may be difficult to track which names in scope are intended to be passed implicitly in larger programs so I tend to prefer systems with an explicit `implicit` qualifier of some form when introduced - but this may also be my lack of experience with languages using name-based implicits speaking.
1
u/Inconstant_Moo 🧿 Pipefish Apr 27 '26
I've never used a language which does like this, so maybe I'm missing something, but it's always seemed to me that implicits are too much magic for too small a return. I don't mind a little more typing. Explicit is better than implicit.
3
u/-Mobius-Strip-Tease- Apr 27 '26
Cool to see! My last post here was to link that paper. How does your implementation differ from their's? Do you have any way to model the "default implementation" idea as well?
3
u/Clementsparrow Apr 27 '26
so... just a special case of default values for parameters, where the default value is the thing with the same name as the parameter in the current scope?
Is it just syntax sugar for default values, or do you intend not to have default values?
1
u/JaSuperior Apr 29 '26
TBH, the indirection has little pay off... And in the worst case, creates a scenario where implicits bind unexpectedly to scoped variables of the same name as the implicit. IDK, seems like alot of ceremony for very little benefit. Can you explain why this pattern would be preferable? I can imagine a situation where I've defined a variable in scope that I didnt intend to bind to a function parameter, but it gets bound implicitly because it got caught within the context. Idk, seems bug inducing. 😅 but i can be convinced, just want to hear your response is all.