4 ms·
Can you please elaborate why OCaml is a good choice for writing parsers?
by ashish01 11y ago
Can you please elaborate why OCaml is a good choice for writing parsers?
- def- 11y agohttp://flint.cs.yale.edu/cs421/case-for-ml.html http://flint.cs.yale.edu/cs421/case-for-ml.html
- chucksmash 11y agoPut me in the "most boring interests ever" category, but I'd be interested in a discussion of the actuarial modeling DSL mentioned in link if said write up exists. I imagine actuaries are about the most technical "nontechnical" users there are so a DSL seems a particularly good fit.
- chubot 11y agoI usually post the VandenBerghe link too. It's basically advocating the ML subset of OCaml, Haskell, and now Rust. Those languages all feature algebraic data types and pattern matching, which were pioneered in ML. Rust is basically a cross between ML and C++, with C-ish syntax. http://en.wikipedia.org/wiki/ML_(programming_language) http://en.wikipedia.org/wiki/ML_(programming_language) (None of C, C++, Java, JavaScript, Python, etc. have those features, and thus they are all suboptimal for writing parsers.) A good clue is the name -- ML stands for "meta-language". It's literally a language for describing languages. ADTs and pattern matching are basically two sides to the same coin -- data vs code. ADTs are how you describe variants in the data. Specifically, "sum types" are essentially type-safe tagged unions (if you are a C person). And pattern matching is how you describe variants in the code. The compiler checks that you have considered all cases. This helps you tame code with nested conditionals. Nested conditionals give rise to the state space and code path explosion that I mentioned. Here is more recent explanation: https://queue.acm.org/detail.cfm?id=2038036 https://queue.acm.org/detail.cfm?id=2038036 Take a look at the OCaml vs Java code snippets.