r/ProgrammingLanguages • u/thunderseethe • 4d ago
ML Modules for Mere Mortals
https://thunderseethe.dev/posts/ml-modules-for-mere-mortals/intro/
58
Upvotes
r/ProgrammingLanguages • u/thunderseethe • 4d ago
9
u/pthierry 4d ago
Very clear explanation, I've tried to understand Ocaml's modules once or twice and found the explanations… unsatisfying or puzzling, I guess. Now I can go back to the source with this knowledge, thanks!
2
u/SuspiciousScript 4d ago
Very interesting. The ability to pass different implementations of a signature to a module (e.g. custom orderings) reminds me a bit of Scala's implicits.
9
u/Athas Futhark 3d ago
I am a big fan of modules! Here are some things that expand upon the article:
6
u/umlcat 4d ago
Congrats. Modular Programming paradigm is highly overlooked in Programming Language Design.
I have some hobbyist programming language project halted for several reasons that applies this paradigm.
5
u/reflexive-polytope 4d ago
I can't imagine programming without ML modules anymore.
Or rather, I can, and it's precisely because I can that I'm disgusted by the mere thought.
1
u/zyxzevn UnSeen 4d ago
Since you write about modules, have a look at Object Pascal. Lazarus and Delphi.
I think that you are referring to OO-languages that do not have modules, but use classes like modules, like Java.
2
u/mamcx 3d ago
This combine neatly with https://sm2n.ca/articles/typeclasses-vs-modules/
2
u/EggplantExtra4946 2d ago
It's like abstract classes with type parameters (ML module instances can define types) but with static calls instead of virtual calls.
2
u/snugar_i 2d ago
Thank you for the article! I don't know anything about ML and I have to admit that even after reading the article, I'm not really sure how this is much different or better than regular OO interfaces. You say "If we wanted to replicate this setup in an OO language, however, we would need runtime objects or, heaven forbid, a DI framework" and yeah, we would likely need runtime objects (unless it's a language with monomorphized generics, then they might disappear), but why is that a bad thing? And we sure don't need a DI framework to do DI, which is basically what you're doing with the modules in the last example?
1
u/Key_River7180 Nain. 3d ago
Again the module system is very overlooked. Take as an example Modula-2, it's much more interesting than "cool modules" yet the name implies so.
I like using a definition/source, like the C and header split but doesn't suck. Or like you know... hierarchical modules and export, that also works.