r/ProgrammingLanguages • bruijn, effekt • Apr 27 '26

Discussion Effekt: Name-Based Implicits

https://effekt-lang.org/tour/name-based-implicits

We 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

17 comments sorted by

View all comments

Show parent comment

1

u/_marzipankaiser_ Effekt Apr 29 '26

I think "marking" names to be used for implicit resolution when they are defined locally could be a reasonable addition. For many cases, the global (or namespaced) definitions are what we want in most cases (e.g., for functions like show, compare, equality etc). While being able to have a local show, e.g., is quite useful sometimes, I'd be fine with having it be more qualified. (This is not the case because 1. I'm somewhat lazy and this would have added to the implementation effort and 2. I did not think of this when implementing it, probably mostly because Koka doesn't do it). As for the lack of experience with languages doing this: I think there are very few that do this at this point, so few people will (and I do neither - I will once this has been in Effekt for some time).

As for name-based vs type-based, part of this is addressed in Koka by allowing "namespaced" parameters, so writing something like int::ord as the parameter name (which is already possible in the current development version of Effekt, so will be in the release on Monday). When using implicit parameters to do "something like typeclasses", I do prefer the names making a difference, though: A function (A, A) => Bool can be anything really, so you have to make the distinction in the type somehow. With type-based implicits, you can define a "Eq[A]" type that you can distinguish from a "LessThan[A]" type or any other binary predicate, introducing further indirection (you have to explicitly define all of the Eq[A]s, wrap/unwrap them in some places, ...). This also means that it only works for things that are already intended to be used like this, or by manually repeating the list of all definitions (to make the respective Eq[A]s). A nice thing about the name-based version is that the definitions are the same that you'd reasonably have come up with before having implicits. In fact, without changing the standard library, taking show or equality as an implicit parameter already works just fine, even when the person writing them did not know about implicits.