InnocentZero's Treasure Chest

HomeFeedAbout MeList of interesting people

05 Jul 2025

Experiments with OCaml - part 3

Starting out - Emacs config

Ok, so the error last time was the fact that emacs was not able to pick up the change in ocaml switches, hence I restarted for my compositor to pick my settings and emacs picked it up wonderfully. Next, Fira Code ligatures were actually insanely annoying in emacs so I switched to ProFont, and it looks wonderful. Third, dune and dune-format packages are lifesavers.

Large scale testing

Ok, now I'm testing the tokenization of a file. We'll follow the usual logic and read from the file, and then compare the results with the og. And that was surprisingly straightforward! One thing I loved was how dune respects the test dependencies and provides ways to let the dependency be managed for the test.

AST Generation

I started generating an AST, mostly going for recursive descent parsing. I'm going for the "have total functions everywhere" paradigm. I'd like for it to eventually have Result type instead of the Option type that I'm returning everywhere, but for the first stages this seems fine to me. The pattern matching is really powerful and helpful, though I do miss Rust's "?" operator on Results and Options. Anyways, I'm not completing it entirely right now, maybe later.

Tags: programming ocaml

Other posts
Creative Commons License
This website by Md Isfarul Haque is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.