3 ms·
What that means is that the language itself has no built-in constructs to distinguish Unicode, or any other encoding by default. OCaml's string type is more ak
by laylomo2 9y ago
What that means is that the language itself has no built-in constructs to distinguish Unicode, or any other encoding by default.
OCaml's string type is more akin to an array of chars in C, in that it just represents a series of bytes. There's nothing about the string type that describes the contents of the bytes. So while you could put ascii in there, when you to print the contents, it's up to the terminal emulator to decide how to interpret those bytes.
One thing which you can do is include Unicode characters and save them in an OCaml source file. The string type will capture the byte representation just fine.
If you want to enrich the string type to also include format information, you might have to look for other libraries.
And, one last point about the string type: traditionally the string type allowed for mutation. In the last few years this behavior has been deprecated, and in the latest version of Ocaml (4.06), a compiler flag -safe-string has been enabled by default. This makes string immutable, and the traditional behavior has been moved to a new type called bytes.
- jarpineh 9y agoThank you for this concise explanation. This doesn't seem insurmountable at all.