4 ms·
I looked at ReasonML couple weeks back intrigued by Jared's post (referenced in this thread as well) I noticed mentions about OCaml not supporting Unicode. I wa
by jarpineh 9y ago
I looked at ReasonML couple weeks back intrigued by Jared's post (referenced in this thread as well) I noticed mentions about OCaml not supporting Unicode. I was wondering what does that actually mean? If you target native you have to find good external libraries for Unicode string manipulation? Or that text handling in OCaml (and thus Reason) is harder compared to facilities in, say, JavaScript and Python?
Other than that bit Reason React looks very promising. My usual use case tends to start with arbitrary JSON source I'd like to build a tool for. Due to strict typing this runs headlong into hurdles that have ended my explorations...
- laylomo2 9y agoWhat 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.
- yawaramin 9y agoThe standard Unicode library in native OCaml is Camomile https://github.com/yoriyuki/Camomile https://github.com/yoriyuki/Camomile (docs at http://docs.mirage.io/camomile/index.html http://docs.mirage.io/camomile/index.html –unfortunately, it's pretty bare-bones). If you're targeting JavaScript with Reason/BuckleScript, e.g. making a ReasonReact app, you will automatically get Unicode support for strings if you use the {j|Unicode string literal|j} syntax (specially provided by BuckleScript).
- jarpineh 9y agoAh, good to know. Main point is that Unicode is not a problem however cumbersome it might get.