My main point was that modular implicits are a very long term research project with no prospect of landing anytime soon. So, if you actually need to do work in this area now, then you have to go with the language that we have. And that means finding a different way to map this abstraction. Maybe you need to do some flamba2 work or whatever to make it performant. And maybe doing it will surface other issues and other options.
But, for data science and linear algebra work, the main issue is notation. The other features of modular implicits are less important because the type-level stuff doesn’t buy you much in terms of safety here. The true types needed are dependent types. And last I checked, for data frames, having a correctly specified dependently typed interface was still a research project. Any type-level thing you do short of that is going to be some approximation and you are still going to have run-time checks and decisions.
I was using multimethods as an example of an alternative solution that exists. Similarly, C++'s Eigen library is extremely fast and makes due without even that. Array programming languages get by despite being unityped. I haven’t seen a good argument, beyond notation, that shows why typeclasses / modular implicits is the best approximation of the relevant types to the exclusion of all other approaches.
The point was simply that there are other approaches that other languages have taken that are being excluded by assumption here. Some of them might be easier to encode into OCaml’s current type system in a way that provides more notational convenience that you currently get with Owl.
I gave almost no thought to the details of how to implement multimethods using polymorphic variants, but the gist of the idea was to hand code (or ppx) the dispatch function by matching on all the cases for all of the arguments. So you’d have one normal function that “figures out” which actual function it should call based on the types of the arguments.
The goal was simply to be illustrative. I don’t use Owl enough to actually know what the correct solution is. Or where the roughest parts of the usability are. But I do know that everyone insisting we need modular implicits isn’t going to make the research happen any faster or fix any actual problems people are having right now today.
In fact, maybe what Owl does now is actually fine and we just need some more elaborate ppx stuff to make the syntax better. (I have yet to see a compelling illustration of why this isn’t possible.)
Worst case scenario, modules can do everything typeclasses can do. They are just syntactically heavier. So you could, if you had to, write a DSL for scientific code that turned “typeclass” specifications into a bunch of module definitions and then made your code explicit about what was going on. Doing it as a DSL would probably be easier than having to do it in the general case as part of the language, especially since scientific code is fairly straightforward by comparison to the general case.
But again, this is something the people who need this solution should experiment with. That or they need to convince someone capable of implementing modular implicits to make it a real priority instead of a “someday maybe” thing.
But nothing is going to change if everyone just holds their breath for a research feature that may never land. And if that feature is really and truly necessary, and none of the alternatives are workable, then, at least for the time being, OCaml just isn’t an appropriate language for that kind of code.