Ocaml Implementation

I had a little problem with implementing arrays in ocaml. For example, when on the terminal (console) and I type

let tab = Array.make 5 6; 

I have

 val tab : int array = [|6; 6; 6; 6; 6|] 

as a conclusion. Therefore, it creates an array of length 5 and fills all cases with 6. Well, I understand this part. But when I print it in a text editor, for example, kate, save it and compile, I get this error:

 Error: Unbound value Array.make 

I do not understand why Array is required for this. make as a value in kate, and it takes Array.make as a function in the terminal. I saved the file with the extension ".ml" and I will compile it using ocamlc -o test name_of_file . Any suggestions please? Thanks.

+7
source share
2 answers

I compiled your program using ocamlc and everything went fine (using OCaml 3.12.0).

I would suggest that you call the old version of the compiler when you are trying to compile, perhaps one when Array.make was still named Array.create . Perhaps when you installed the new version, you overwrote some files (for example, toplevel), but not others (for example, the compiler). To check, compare the versions given by ocamlc -v and ocaml .

As for the "Unbound value" message, in OCaml, functions are values. The developers did not distinguish between “Unbound value which is not a function” and “Unbound value which is a function”, but this is not the cause of the problem. The cause of your problem is that Array.make is not tied at all.

+5
source

I found a mistake. It is so stupid. I saved the file as "array.ml". Therefore, during compilation, he created the file array.cmi, and I think it confused this file a little with the one found in ... /lib/ocaml/array.cmi. I'm not quite sure. So I renamed the file to "table.ml" and it compiled perfectly. It's crazy that he confused these two files

+3
source

All Articles