I am completely new to Ocaml and I am trying to convert between utf8 and unicode code points. But unfortunately I am already stuck at calling the functions in the modules correctly. This is my code:
open Core
let () =
let c = Uchar.of_scalar 0x20ac in
match c with
| Some v → Printf.printf “item is %s\n” (Uchar.Utf8.to_string v)
| None → Printf.printf “Nothing”
The compiler complains about “Unbound module Uchar.Utf8”.
What am I doing wrong?
Thank you in advance for your help!
markusr
@jbeckford: You were right of course! My installation is just two days old, so I automatically checked the latest docs of Core and did not realise, that on my platform v0.17.x is not available yet. Thanks for your help and for the quick response.
# let uchar_to_utf_8 u =
let b = Bytes.create (Uchar.utf_8_byte_length u) in
ignore (Bytes.set_utf_8_uchar b 0 u);
Bytes.unsafe_to_string b
;;
val uchar_to_utf_8 : Uchar.t -> string = <fun>
# uchar_to_utf_8 (Uchar.of_int 0x20AC);;
- : string = "€"