3 ms·
The paragraph type in his OCaml program is a compelling reason for why it OCaml is well-suited for writing compilers: type paragraph = Normal of par_te
by scott_s 18y ago
The paragraph type in his OCaml program is a compelling reason for why it OCaml is well-suited for writing compilers:
type paragraph =
Normal of par_text
| Pre of string * string option
| Heading of int * par_text
| Quote of paragraph list
| Ulist of paragraph list * paragraph list list
| Olist of paragraph list * paragraph list list
The type definition is stated almost the same as the grammar rule would be.
- silentbicycle 18y agoOCaml is exceptionally well-suited to writing compilers, or anything dealing with complex structures of tagged data, really. (See, for instance, http://flint.cs.yale.edu/cs421/case-for-ml.html http://flint.cs.yale.edu/cs421/case-for-ml.html ) It's a neat language. It's got some implementation and usability quirks, and it seems to have a rather small / quiet community (so there aren't many books, though this one is quite good, IMHO: http://caml.inria.fr/pub/docs/oreilly-book/ http://caml.inria.fr/pub/docs/oreilly-book/ ), but it's worth a look.
- scott_s 18y agoI've been reading through The Objective Caml Tutorial, http://www.ocaml-tutorial.org/ http://www.ocaml-tutorial.org/, but I've yet had an opportunity to implement anything with OCaml. I've actually that essay already about how OCaml is good for compilers, but it really struck me with this example.
- Zak 18y agoHaskell, using Parsec seems to have the same kind of advantage. Being new to the language, I've found Parsec shockingly easy to use.