开发者

accessing OCaml records

开发者 https://www.devze.com 2023-01-03 13:03 出处:网络
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:

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 accessi开发者_运维百科ng the module in which the record is defined, but I've yet to get the syntax right.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号