tags:

views:

38

answers:

1

How can I use some OCaml record that I've defined in some other file? Say for example that I have the file a.ml in which I define the r record:

type r = { i: int; j: int; };

and a file b.ml in which I want to use the r record. Something like this:

let s = {i = 12; j = 15;} clearly doesn't work - I know it has something to do with accessing the module in which the record is defined, but I've yet to get the syntax right.

+5  A: 

The types and values defined in a.ml live in the module A. So you need to either open A (thereby bringing all definitions from A into scope) or refer to i and j as A.i and A.j respectively.

sepp2k
Ah, hmm, ok ... for me it wasn't working this way because I was doing something like: a.ml would hold the record definition, a.mli wouldn't hold anything related to that record and I was trying to access the record from b.ml. How would one go with such a case - define the record in the interface ? Either ways, thanks for the answer.
hyperboreean
Yes, type definitions that are meant to be used from other files are part of the interface, so they need to be in the mli file if there is one.
sepp2k