Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Thanks!

Though couldn't you associate data with your OCaml modules, too?



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.


I 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.ht...


Then you were right, I should've checked before answering.


No worries. Thanks!




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: