TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Exotic Programming Ideas: Module Systems

157 pointsby rwosyncover 4 years ago

14 comments

horsawlarwayover 4 years ago
Coming in without much OCaml experience, I don&#x27;t really think this is a great demonstration of why this construct has value.<p>I don&#x27;t really want to read a long form description of the OCaml implementation of modules. I want a comparison to the languages he dismissed at the beginning of the article, and a discussion of why this feature has some value that isn&#x27;t provided by those languages.<p>Basically - This feels like a different take on generics to me. There might be a lot of value in how this is implemented when compared to generics in a language like Java&#x2F;C#&#x2F;Typescript, but I didn&#x27;t find that content <i>anywhere</i> in the article...
评论 #25086355 未加载
评论 #25088230 未加载
miki123211over 4 years ago
Zig&#x27;s compile time execution lets you do similar things I believe.<p>In Zig, structs and modules are equivalent, and type declarations can be manipulated at compile time just like any other value. That, among other things[1], lets you write:<p><pre><code> fn LinkedList(comptime T: type) type { return struct { pub const Node = struct { prev: ?*Node, next: ?*Node, data: T, }; first: ?*Node, last: ?*Node, len: usize, }; } </code></pre> I wonder if there&#x27;s anything that OCaml functors can do but this can&#x27;t.<p>[1] for example, you can implement a very efficient printf that gives an error at compile time when the format string is invalid. See <a href="https:&#x2F;&#x2F;ziglang.org&#x2F;documentation&#x2F;master&#x2F;#comptime" rel="nofollow">https:&#x2F;&#x2F;ziglang.org&#x2F;documentation&#x2F;master&#x2F;#comptime</a> for more details.
评论 #25084865 未加载
评论 #25088144 未加载
评论 #25084047 未加载
Drupover 4 years ago
Amusingly, I was precisely working today on extra-nice error messages for module type errors in OCaml. :)<p>My reaction to the title was &quot;But they are not exotic, I use them every day!&quot;<p>It&#x27;s definitely the feature I miss the most every time I work in other languages, even presumable &quot;advanced&quot; ones, like Haskell. One notable attempt to add them elsewhere is &quot;modular C&quot;[1].<p>[1]: <a href="http:&#x2F;&#x2F;cmod.gforge.inria.fr&#x2F;" rel="nofollow">http:&#x2F;&#x2F;cmod.gforge.inria.fr&#x2F;</a>
评论 #25087756 未加载
cultusover 4 years ago
Great read. It&#x27;s too bad modules are pretty much an afterthought in most langs.<p>I really like research language 1ML&#x27;s approach to modules[0]. This allows monomorphic types to be treated like values, avoiding all of OCaml&#x27;s module syntax (which can be a bit complex and verbose).<p><a href="https:&#x2F;&#x2F;people.mpi-sws.org&#x2F;~rossberg&#x2F;1ml&#x2F;1ml-extended.pdf" rel="nofollow">https:&#x2F;&#x2F;people.mpi-sws.org&#x2F;~rossberg&#x2F;1ml&#x2F;1ml-extended.pdf</a>
评论 #25082695 未加载
OkGoDoItover 4 years ago
Other than the syntax, I’m not sure I understand how this is different from any other object-oriented class definition. I suppose the ability to project the module into the local or top-level scope, but that seems more like syntactic sugar than anything meaningful. What am I missing here?
评论 #25083353 未加载
评论 #25083175 未加载
评论 #25083423 未加载
评论 #25085126 未加载
评论 #25082998 未加载
评论 #25082829 未加载
评论 #25082845 未加载
shalabhcover 4 years ago
On the topic of modules, I recommend reading about modules in Newspeak: <a href="https:&#x2F;&#x2F;bracha.org&#x2F;newspeak-modules.pdf" rel="nofollow">https:&#x2F;&#x2F;bracha.org&#x2F;newspeak-modules.pdf</a><p>Modules (which are just top level classes and contain nested classes) have no import statement and no hard linked external dependencies. When you instantiate the module (~class) you pass in dependencies it needs.
pjmlpover 4 years ago
&gt; Modules as a language feature were first developed in Modula-2 and Pascal, which were developed as a way to demarcate units of compilation.<p>Actually Mesa.
评论 #25084087 未加载
jlrubinover 4 years ago
You can do something similar in Rust to ML modules using traits and generic impls as module functors!<p><a href="https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=8bebb69fa7898b13c731ccef158c0e4b" rel="nofollow">https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;mode=debug&amp;editio...</a><p>This can be really useful especially as traits with differing concrete types diverge, you can create a unified interface trait object to allow trait objects for things like container classes.
js8over 4 years ago
Looking forward to the series! I hope, in one of his &quot;presents&quot;, he talks about Lisp conditions and signals, which have also inspired PL&#x2F;I conditions, and go really back to the idea of an error handler in an operating system.<p>Unfortunately, Unix (and C) really botched signals by limiting their number in the user space (in particular, they cannot be stacked), and so the idea largely fell out of favor as an error-handling paradigm.
评论 #25085454 未加载
jandreseover 4 years ago
One thing I like about Perl is the module system.<p>A big helper is when the module interface uses named parameters and has sensible defaults for unspecified parameters. This allows the module designer to add features without breaking existing code and makes it easier for someone to integrate the module in the first place. Having the documentation built into the module itself is also a huge win.
gnulinuxover 4 years ago
I feel like I keep saying this every single PLT-related HN thread. Sorry for preaching, but I just can&#x27;t resist. I think Agda is an excellent programming language, and it&#x27;s a joy to write anything in. Its learning curve is steep at the beginning but once you gain experience how to write coinfinite programs, it&#x27;s such a joy.<p>I think its module system is a huge bonus. It makes code a lot easier to organize and reason. It forces toplevel module X to be defined in X.agda so there is no argument what the module should be named or where it should be found.
flaviousover 4 years ago
I&#x27;m not your goto java guy, but the module system of java and how modules can provide implementations for interfaces is really great.
ellis0nover 4 years ago
Exotic Modules System looks like new C++
ProfSarkovover 4 years ago
Nice (altered) Anna Karenina quote.