3 ms·
Of course modular implicits aren't typeclasses, but they would allow functionality very similar to typeclasses: function polymorphism. Maybe we have a differen
by smabie 6y ago
Of course modular implicits aren't typeclasses, but they would allow functionality very similar to typeclasses: function polymorphism.
Maybe we have a different idea of cumbersome, but I find that having to explicitly find the right >>= or >> to be cumbersome, and it feels bad. Having to implicitly pass modules around or using local open is simply inelegant.
I've found that there's a surprisingly large number of OCaml users who defend the status quo no matter what. OCaml seems to be perfect for them, even though everyone else can see its flaws. I've introduced OCaml to quite a few Haskellers, and all of them have been shocked to learn about the lack of flexibility OCaml provides. OCaml doesn't get anywhere close to providing the kind of "type-level" programming that Scala and Haskell do.
Most of the interesting kind of programming you can do in Haskell is simply not possible with OCaml. While OCaml will never be Haskell and probably shouldn't, modular implicits would go a long way in helping.
Here's a concrete example: ppx_let. ppx_let is a very nice library and makes monadic code a lot nicer. It's fantastic, even if you have to find the right Let_syntax module. I use core, so it's relatively easy to just import the correct one. The problem is when you're using other libraries. For example, angstrom (a parser combinator library) doesn't have a Let_syntax module. So I either have create my own or not use ppx_let with it. Modular implicits could solve this problem.
Another problem is that very few OCaml users are actually using stdlib bundled with OCaml. Personally, I think stdlib should be ditched and replaced with Core_kernel, but this is never going to happen. It's too late to make updates to the collections library, the biggest industrial user, Jane Street, is never going to use them.
About the LLVM IR, it's not what LLVM IR would bring exactly. It's that time and time again, the reason for why so and so is taking so long is that there aren't enough compiler experts. Not enough performance experts for multicore, not enough type experts for modular implicits, etc etc. I am ignorant on OCaml internals, but why are there so few people who can contribute? New masters students who've never touched the Scala compiler, for example, make pretty significant changes all the time. I suspect there is something about how the compiler is written that makes it very hard to understand.
Perhaps if OCaml used LLVM IR, it would simplify things. LLVM can do some pretty impressive optimizations on IR, has a JIT, includes a number of backends, etc etc. There's a reason why almost all new languages use it: because it's easy. Hell, you could create a compiler for a very simple imperative dynamic language (like Python, say) in a weekend that would have pretty impressive performance.
Look, I love OCaml. I like that it produces native executables, I like the practicality, I like the clean syntax, etc. But the language has some major problems: fractured ecosystem, weak type system, strange module system, etc. OCaml does things differently than other languages, and that's fine. But being different has a price, and sometimes, it actually has no benefit. I understand the core language will not change, but I think things modular implicits could be a game-changer in terms of usability. OCaml wouldn't look so weird anymore. Maybe it could even be used for scientific computing.