What's the function of Uchar?


Howdy! What’s the de facto use case for the Uchar.t type and Uchar module? It doesn’t seem to provide much real functionality. (For example, there’s nothing to turn a Uchar.t into a string of utf8 chars or what have you, nor have I seen something in the standard library that turns a utf8 sequence in a string into a Uchar.t.) I’ve also not noticed it being used elsewhere in the standard library. There’s no printf format character for a Uchar.t.

Is it a matter of it being intended for future use?


From what I know, the Uchar module is intended for compatibility between libraries that manipulate unicode, so that all libraries share the same type for unicode characters (as stated in the documentation of the module).

You might be interested in reading the dicussion that lead to the addition of the module (in the associated github pull request).

I personally use the Uucp and Uutf libraries in my projects, both of which use the Uchar.t type.


Another PR of interest is this one which allows to encode Uchar.t values into Buffer.t and made it in the upcoming 4.06.

If you are interested in OCaml and Unicode there’s also this one for 4.06 but it’s OT for this thread.


Thank you, all of those links are quite helpful!

Any chance of printf or similar support showing up? It would be helpful for debugging.