4

I'm working with multiple files, and i have a problem with one mutable field. In file1.ml, i declared:

type mytype = {
     mutable numbers : int list;
}

So, in file2.ml, i have elements of type mytype. But, when i'm trying to make:

myElement.numbers

The following error is returned: Error: Unbound record field label numbers.

Thanks, any help is welcome.

Thomash
  • 6,339
  • 1
  • 30
  • 50
6c656c
  • 312
  • 2
  • 14
  • One way to think about it is that the thing you're defining is not record, but record selectors. So when you use a selector, you have to state its full path. – lebowski Mar 29 '13 at 18:37

1 Answers1

5

Use a fully qualified name from file2: myElement.File1.numbers

or add an open File to your file.

or use local module opens let open File2 in myElement.numbers

rgrinberg
  • 9,638
  • 7
  • 27
  • 44
  • Worked with the first option! But, i forget to explain that my File1.ml has one module, and myType is inserted in "myModule". How can i fix it with "open File"? "open myModule"? – 6c656c Mar 28 '13 at 14:25
  • 2
    You should be able to use `open File1.myModule`. Stylistically it's good to work toward having only a very few global uses of `open` in your code. Otherwise you have to work too hard to keep your namespaces free of conflicting names. If you're just starting with OCaml you can worry about this later. – Jeffrey Scofield Mar 28 '13 at 14:42
  • 2
    note that this "problem" should disappear with future versions of OCaml (there was already working code in the development tree last time I tried it). – didierc Mar 28 '13 at 22:09