Hacker News new | past | comments | ask | show | jobs | submit login

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.



OCaml 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 )

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/ ), but it's worth a look.


I've been reading through The Objective Caml Tutorial, 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.


Haskell, using Parsec seems to have the same kind of advantage. Being new to the language, I've found Parsec shockingly easy to use.


What have you been using to learn how to use Parsec?


The Parsec manual. I wrote a fairly simple log file parser as a practice project.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: