Has anyone used phantom/obscure types for metric units?

F# has a nice feature that the other day I wished to have on Typescript: metric units.
Basically I was trying to format a number that was on milliseconds like they were minutes. Took me several minutes to figure out the problem.
Then I asked myself: will it be possible to simulate this on rescript/ocaml? I think it can be possible hiding the module types, but will it be comfortable to use?


Opaque types are really nice to use from the consumer’s perspective in ReScript in my experience, although they’re slightly annoying from the module writer’s perspective. Making the type opaque via interfaces or module types feels like a lot of boilerplate to me.

Elm has a very nice package for these


Could be good inspiration

1 Like