Demonstration of the extension literals and constant rewriting features

Yo! :yoyo: :waving_hand:

I started learning the beautiful ppxlib library and found interesting information in their documentation about OCaml’s syntax features, such as extension literals - the ability to append a one-letter identifier to numeric literals. I was surprised at how easy it was to do this.

Because I was inspired by this, I wrote a demonstration project (located in my GitHub repository) to show how to use it to implement metric system support in code.

utop # 5m;; 
- : Metric.Meter.t = 5

utop # Metric.Meter.(1m + 10m);;
- : Metric.Meter.t = 11

References:

4 Likes

Cool demo. I was thinking about this the other day. Unfortunately, the feature is very limited–the suffix can only be a single character in the set [G-Zg-z]. It might end up being more convenient to just use normal functions like m 1 and so on.

1 Like