Where does caml_copy_string live?

caml_copy_string is part of the collection of functions for interfacing with C:

Is this supposed to be available in utop by default, or at all?

# caml_copy_string;;
Error: Unbound value caml_copy_string

What do I need to #require or open to have this available?

I don’t actually want to use this function in utop. I’m just trying to debug a problem with using the Hdf5_caml module from the hdf5-caml package.

I have skimmed the “Interfacing with C” documentation linked above, I haven’t read it thoroughly. It’s not at all obvious whether the answer to my question is there, and since I don’t have a need to interface with C in my own code, I would rather not dive into the details of the documentation just to answer some simple questions. Thanks in advance.

It’s defined in caml/alloc.h, a standard include when you write C that will interface with OCaml. Since it’s defined as working on a char const *, it may not be available in OCaml at all (i.e., there is nothing you can require or open to get it.)

You have better luck asking about your actual problem with hdf5-caml.

Thanks very much @techate. That’s extremely helpful. It makes sense now that you state it. (I had asked about the error I was getting in an hdf5-caml issue, but the response I got suggested that I shouldn’t get an error when I #require Hdf5_caml, so I wanted to get a broader understanding of caml_string_copy and what might be going on. Perhaps Hdf5_caml can only be used in compiled code–not in utop–but I’m having trouble with the former as well. But that’s a different issue, I think.)

I also have the same issue (OCaml: 4.04.0, OPAM: 2.0.0~beta, ). Current I fall back to its 0.1.3 version and it works fine in utop so I think it’s quite likely that Hdf5_caml is also meant for being used in utop.

Good to know it’s not just my configuration. Using 0.1.3 seems like a good solution for now. At this point I’m just trying to learn about hdf5-ocaml.

(I have the sense that OCaml users vary in how much they depend on utop. Some people may focus almost exclusively on compiled executables and miss problems in the repl at first. That’s understandable.)

vbrankov (hdf5-ocaml's author) said that there’s a bug with strings in 0.1.3, so that version might not be suitable for production work. https://github.com/vbrankov/hdf5-ocaml/issues/9#issuecomment-350466293

1 Like