Another problem is that an immutable singleton could have interesting properties, like it could have a type, it could be polymorphic (e.g. think Scala's objects), but this article presents Ocaml modules to be nothing more than namespaces. So first of all, that's not true and furthermore, I don't see the usefulness in that compared to any other language that can do namespaces. When reading about some construct of a language I don't know, I want to see how that construct is different or useful for me.
As I'm writing this, the article has 42 points and I'm left wondering why. I've long suspected that HN votes articles by keywords happening in the titles, without reading the articles.
I haven't read the article, but it would be great if whoever submits an article also had to enter one or more questions (with yes/no answers or one-word unambiguous answers) about it. Then, upon submitting a vote for the article, HN would prompt users to answer them. A suggestion to read the fine article would be given to people who cannot answer, and no upvote would happen.
Someone writes a blog post, using JavaScript to explain how modules are used in OCaml. Just in the case it changed during the last 20 years or so.
Edit: I'm glad more people learn about OCaml. A few years ago, I kept hearing that no one will contribute to my open source OCaml projects...
Haskell's "constrained" types look like this
c => a
where the type `a` requires access to the details of a constraint `c`. It turns out that constraints are merely type parameterized dictionaries of functions acting upon those types. We could reify them into concrete data types if we liked and then replace the fat arrow (Dict of c) -> a
and get something functionally equivalent.Now, instead of doing that Haskell has the typeclass mechanism which allows the compiler to automatically generate and pass needed constraints based on a prolog-like logic that executes at compile time. This can be convenient but restricts the flexibility of these dictionaries.
ML modules can do some of the very same things but require the user to manually wire the proper module in at the right time instead of letting the compiler do it [0]. The benefit is that your modules are more modular and can support more sophistication.
[0] Caveat: this compiler automatic dictionary wiring will be enabled, in part, with OCaml's modular implicits which are coming down the pike soon.
On the other hand, you can also use modules as a simple namespacing mechanism (as in Haskell modules). But this does not capture the full power of the module system.
Cool... I guess?