I really don’t understand why I have not seen any resistance to implicits in the discussions I’ve read. Also I just saw Janestreets latest video where Yaron Minsky said that everybody in the OCaml community wants the feature.
My impression of OCaml as a language, as it is now, is that one of its strong suits is exactly its explicitness. I agree that the examples where implicits are used in a less-than-screen-long example, then they seem ‘nice’ - but this is not what the code is going to look like when
- it is used on more complex problems
- when there are more than 5 implicit modules in scope
- when the implicits are used so often, that they will get opened in the top of the file instead of locally
I’ve been working a couple of years now with Scala in my job, and implicits has in my experience not been a win at any point - if you want readable code. Of course, in scala it gets many times worse, as people making libraries intermix implicits with reflection, macros and subtyping. I have to remind myself that this is probably also a cultural problem with the Scala community.
I have an ideal for functional code that I see is potentially getting undermined by a feature like implicits:
Functional code can be really easy to jump into, as there is only input and output - the only thing one has to know to understand the code, are the functions being used locally, and what type of values you have.
The problems that arise are:
- When implicits are opened in scope somewhere, one can’t reason locally about which functions are getting called.
- When a library is written with heavy usage of implicits, one has to know the whole library to be able to understand exactly what the big block of code using it is doing.
- When many datatypes have the same functions available in the same scope, and you have a longer chain of functions that map from datatype to datatype; then you have to keep state in your head about what function is called at which point in the chain, else you can get the wrong semantics when you refactor. (This problem is probably enlarged in scala because of subtyping)
What happens is that without “implicits” you have an explicit program, and you have a bit of implicit knowledge of the datatypes and algorithms in your head. Then comes “implicits”, and you get an implicit program, where you in turn need to keep track the before explicit knowledge in your head too.
Keeping state in your head is exactly what I want to minimize, and this feature is not something I’ve seen helps this.