Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing OCaml records

Tags:

record

ocaml

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.

like image 988
hyperboreean Avatar asked Jun 13 '10 18:06

hyperboreean


1 Answers

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.

like image 159
sepp2k Avatar answered Sep 23 '22 00:09

sepp2k