1

I have some code that uses the module Big_int, like in:

open Big_int;;
Big_int.gcd_big_int 5 6;;

However, when I compile this with utop dune utop --release (I use release to avoid some warnings), then I get this error:

Error: Required module `Big_int' is unavailable

I have read about it and I have read (https://groups.google.com/g/felix-language/c/1CfHgpe9zps?pli=1) that 'Big_int is no longer part of the OCaml distribution. It was replaced by Zarith'. Well, I know that, but also that I can still use Big_int.

How do I know it? The point is that if I start utop with any other file that has no errors, and once inside I open Big_int, then it does not regret:

utop # open Big_int;;

Once there, it autocompletes my Big_int., like in Big_int.add_big_int. So there Big_int is there somewhere and it is recognised (VSCode also autocompletes it).

There is something I am not understanding. Any help?

Theo Deep
  • 666
  • 4
  • 15

1 Answers1

2

For compatibility reasons, the binary files for the num library are still installed (in 2021) in the compiler directory. This is what you are seeing in utop.

However, num is deprecated in favor of Zarith.

If for some imperious needs, you need to use num, you need to declare it as a dependency in your project's dune file before using it with dune utop.

octachron
  • 17,178
  • 2
  • 16
  • 23
  • I see... I do not understand this: 'declare it as a dependency in your project's dune before using it'. You mean as a whole directory or something? – Theo Deep May 11 '21 at 13:14
  • 1
    The entry in the `dune` file corresponding to your library must declare its dependency on `num`: (library (name libname) (libraries num ... ) .... ) – octachron May 11 '21 at 13:56
  • That works!! Lots of thanks. One last question, please. I am inside utop: ```utop #...``` and therefore I can use any of the libraries that have been charged on its files, like ```num```. Now, how can I call a function of any of my files that have been charged? Like in ```Big_int.add_big_int``` I have tried ```my_file.one_function```, but it does not work. – Theo Deep May 11 '21 at 14:20
  • 1
    By default `dune` wraps modules inside a library module etrnypoint. Thus you need to use `Libname.My_file.f` – octachron May 11 '21 at 15:34
  • Completely fine. Thanks! – Theo Deep May 11 '21 at 16:10