<story><title>My thoughts on OCaml</title><url>https://osa1.net/posts/2023-04-24-ocaml-thoughts.html</url></story><parent_chain><item><author>spqr233</author><text>I don&amp;#x27;t the author really gave Ocaml a chance. He argues that every language needs to have interfaces. I agree somewhat with that statement, but I think the truer statement is to say that every language needs to have some way of defining composition at a structural level.&lt;p&gt;An interface allows you to pass different &amp;quot;structures&amp;quot; to the same function so long as they adhere to the same spec. In Ocaml this is accomplished through modules, functors, and module signatures. Ocaml&amp;#x27;s module signature can play the same exact role as interfaces in Haskell, Rust or F#.&lt;p&gt;The module system is arguably more expressive than what can be accomplished to interfaces. To give an example, Ocaml suffers from the same problem as rust does with having two standard implementations of a async runtime. Just like rusts: tokio and async-std, ocaml has Lwt, Async, (and newly added to the mix Eio).&lt;p&gt;Whereas in rust most libraries just implement one of these systems, and you&amp;#x27;ll have to use compiler directives to support both. Ocaml&amp;#x27;s module system means that you can describe the async runtime as a signature and make your entire library generic to the async runtime it runs on top of. Most of the well-used libraries do this, and so you don&amp;#x27;t have to worry too much about which runtime you decide to use.&lt;p&gt;Clearly, a language that can do that must have in some place a system that can replace interfaces.</text></item></parent_chain><comment><author>hardwaregeek</author><text>Politely, I feel like this is the issue with OCaml as a community. You gave a beautiful answer about programming language design and composition. But how does it feel to write the language? How can you print a user defined data type? From reading around, it seems like your options are: explicitly pass a print function for that specific type, use a third party library for printing, or (my &amp;quot;favorite&amp;quot;) don&amp;#x27;t. Or how does it feel to write a function that takes a generic that can be printed, checked for equality, and read? Or to convert one type into another type?&lt;p&gt;And we&amp;#x27;re still talking about semantics here. How does it feel to use the language server? How does it feel to read the code? To build the language? Ultimately that&amp;#x27;s what users judge a language on. Yes, Rust in some ways has a worse form of abstraction. It is global, not fully generic and doesn&amp;#x27;t allow for overloading. But it creates a user experience that is nicer. It lets a user print something and compare two variables and do type conversions without having to scratch their head, read a forum post and import a library.</text></comment>
<story><title>My thoughts on OCaml</title><url>https://osa1.net/posts/2023-04-24-ocaml-thoughts.html</url></story><parent_chain><item><author>spqr233</author><text>I don&amp;#x27;t the author really gave Ocaml a chance. He argues that every language needs to have interfaces. I agree somewhat with that statement, but I think the truer statement is to say that every language needs to have some way of defining composition at a structural level.&lt;p&gt;An interface allows you to pass different &amp;quot;structures&amp;quot; to the same function so long as they adhere to the same spec. In Ocaml this is accomplished through modules, functors, and module signatures. Ocaml&amp;#x27;s module signature can play the same exact role as interfaces in Haskell, Rust or F#.&lt;p&gt;The module system is arguably more expressive than what can be accomplished to interfaces. To give an example, Ocaml suffers from the same problem as rust does with having two standard implementations of a async runtime. Just like rusts: tokio and async-std, ocaml has Lwt, Async, (and newly added to the mix Eio).&lt;p&gt;Whereas in rust most libraries just implement one of these systems, and you&amp;#x27;ll have to use compiler directives to support both. Ocaml&amp;#x27;s module system means that you can describe the async runtime as a signature and make your entire library generic to the async runtime it runs on top of. Most of the well-used libraries do this, and so you don&amp;#x27;t have to worry too much about which runtime you decide to use.&lt;p&gt;Clearly, a language that can do that must have in some place a system that can replace interfaces.</text></item></parent_chain><comment><author>v0idzer0</author><text>Came here to make this exact point. But I totally agree with all of his other complaints. It’s a good list of the cons, but ignored the many pros</text></comment>