4 ms·
A key difference from OCaml's modules (besides the lack of type parameterization) is Liskov's data types have associated data. So it's more like Rust's structs.
by kirillkh 9y ago
A key difference from OCaml's modules (besides the lack of type parameterization) is Liskov's data types have associated data. So it's more like Rust's structs. Also, like in Rust, there is no support for multiple implementations of a single signature.
- eru 9y agoThanks! Though couldn't you associate data with your OCaml modules, too?
- kirillkh 9y agoIt'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...