Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my string of type `bytes`?

According to Real World OCaml, the type of "abc" should be string. But actually in my utop REPL, it's of type bytes.

I've already opened Core.Std. Why is that?

(The version of OCaml is 4.02.2; Core is 112.24.01; utop is 1.18.)

like image 972
Ben Avatar asked Jul 19 '15 11:07

Ben


1 Answers

You must enable safe string mode explicitly. Just start utop with:

$ utop -safe-string

Before the introduction of type bytes in OCaml 4.02, strings were mutable. Now, strings are intended to be immutable, and bytes is the type to be used for "mutable strings".

In order not to break too much existing code, this distinction is not yet enabled by default. In default mode, bytes and string are synonymous.

like image 67
rafix Avatar answered Sep 18 '22 19:09

rafix