Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ocaml implementation

Tags:

arrays

ocaml

I got a slight problem implementing arrays in ocaml. For example, when on the terminal(konsole) and I type

let tab = Array.make 5 6;

I have

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

as an output. So it creates an array with a length of 5 and fills all the cases with 6. Okay I understand that part. But when I type it on a text editor like kate for example, save it and compile it it I get this error:

Error: Unbound value Array.make

I don't understand why it takes Array. make as a value in kate and it takes Array.make as a function in the terminal. I saved the file with the ".ml" extension and I compile it using ocamlc -o test name_of_file. Any suggestions please? Thanks.

like image 246
mkab Avatar asked Mar 27 '11 17:03

mkab


2 Answers

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

I would guess that you are calling an old version of the compiler when you try to compile, perhaps one from when Array.make was still named Array.create. Perhaps when you installed the new version, you overwrote some of the files (such as the toplevel) but not others (such as the compiler). In order to check, compare the versions given by ocamlc -v and ocaml.

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

like image 184
Pascal Cuoq Avatar answered Nov 05 '22 16:11

Pascal Cuoq


I found the error. It's a very stupid one. I saved my file as "array.ml". So during the compilation it created an array.cmi file and I think it kinda confused this file with the one found in .../lib/ocaml/array.cmi. I'm not really sure. So I renamed the file to "table.ml" and it compiled perfectly. It's crazy that it confused these two files

like image 28
mkab Avatar answered Nov 05 '22 15:11

mkab