5 ms·
A language like ocaml excels when the input and output are program-like, and the problem can't be number-crunched by hardware. The typical example would be a co
by jlouis 3y ago
A language like ocaml excels when the input and output are program-like, and the problem can't be number-crunched by hardware. The typical example would be a compiler. Other examples would be model checkers, code generators for number crunching libraries, proof assistants, and so on. Complex problems, where you need to explore different avenues of approach quickly, and where symbolic manipulation is at the heart of the problem.
Thus, ocaml is best used as a "kernel" or "module". The contextual part of your system uses the part written in ocaml as a service.
But ocaml doesn't excel at problems which are common to a typical company. The people who are in the intersection of wanting to solve those problems, and ocaml developers are few. The same intersection with a more mainstream language is far larger.
However, if you find yourself with a problem at which ocaml excels, chances are the mainstream languages ends up falling short very quickly, because they tend to lack the abstraction features necessary for correctly handling the complexity.
- riku_iki 3y agoThe question is if modern versions of popular languages (java, c#) caught up on ocaml's syntax sugar, or maybe this syntax sugar is trivially replaceable by some utility functions. Maybe you could bring any example of such ocaml functionality?
- belmont_sup 3y agoSyntax and sugar is subjective, right? Instead, easier to discuss the layer beneath syntax, and that’s to compare the type systems. Java now has some version of sum types aka algebraic data types, but because of its beginnings, it may never feel as easy to use. And ease of use is important, as is evident from discussions here. Had to look up to see where Java is at for sum types. First link I found. https://sfietkonstantin.github.io/2021/09/03/Java-sum-type.html https://sfietkonstantin.github.io/2021/09/03/Java-sum-type.h...
- riku_iki 3y agosum types is not something supercritical, it saves few lines of code. Also, somehow I rarely have need to use something like that personally. > And ease of use is important the question is if insignificant syntax sugar worths switching to unpopular platform with undeveloped toolings and uncertain support.
- yawaramin 3y agoSum types save more than a few lines of code, they can save you from nasty bugs thanks to exhaustiveness checking in pattern matches. Once you get used to this you will be hard pressed to go back to prehistoric times.
- riku_iki 3y ago> Sum types save more than a few lines of code, they can save you from nasty bugs thanks to exhaustiveness checking in pattern matches. do you have specific example?
- yawaramin 3y agoLook at this code which prints out an HTML tag: https://github.com/yawaramin/dream-html/blob/main/lib/dream_html.ml#L39 https://github.com/yawaramin/dream-html/blob/main/lib/dream_... Initially you might think generating HTML tags from data structures in code should be a simple matter. But there are complexities--some tags are defined as having no child tags, others do. Some tags are purely character data (unstructured text), not structured data. Some are just comments. We need a way to compose multiple tags together into a single 'virtual' tag for flexible HTML generation. All these conditions can be pretty hard to keep track of--unless your compiler does exhaustiveness checking. Then the compiler will tell you if you missed any cases. In the example above I didn't make any manual effort to cover all the cases, I simple listed out the cases I wanted to handle in order. The compiler made sure that I didn't miss any.
- never_inline 3y agoThis is very specific case though. Many times compiler tooling will do just fine with good old visitor patterns, enums etc.. Sure there may be small amount of errors missed, but that's not always as critical as availability of libraries and integration.