3 ms·
It's been a while since I played with OCaml, but I'm pretty sure that modules are stateless. A quick googling shows that you can use global state, but it's not
by kirillkh 9y ago
It's been a while since I played with OCaml, but I'm pretty sure that modules are stateless. A quick googling shows that you can use global state, but it's not the same as one instance of state per one instance of struct as in Rust.
- eru 9y agoI should have been less tentative: you can add values to modules, and you can add mutable values to modules. And that state is not global at all. (Though you might be able to ask for global state.) They are often used without mutable state, but the language doesn't make them so. See eg https://realworldocaml.org/v1/en/html/first-class-modules.html https://realworldocaml.org/v1/en/html/first-class-modules.ht...