Get bigger number in ReasonML

Hi guys!

If anybody can give me a hand, I really apreciate it.

What happens

I’m solving a challenge where my input is bigger than 2^63 - 1, so the Int64 module isn’t enough.

What do you understand or find about that problem

I don’t know what’s happening

You make any workaround? What did you do?

Yes, I found a this module called Num, but it didn’t work. Also try to coerce the number to float, but of course, it lose precision.

(Optional) Why fails your workaround?

Well, the module isn’t available!


Here is the error:


Also give some versions of the “ecosystem” (because I don’t know how actually Reason is implemented) that make the extension of VsCode:

I need help with

The process of installing Reson was a challenge for me. However I’m compiling the programs with the lines used in the repository.

I don’t know if am I using an old version, or what’s going on.

If anybody could help me to acces the module would be great.


I’ve been reviewing this problem, it seems Reason ML lang doesn’t support Big Integers at this time, the Num module that you mention cannot be used since although it appears in the documentation it’s not supported yet Documentation errors? Bigarray, Num, Unix, etc. · Issue #1931 · reasonml/reason · GitHub, however, to be sure of this, I took the topic directly to the ReasonML forum.

On the other hand I must add that installing most of the repo languages is a very easy task using nix Languages | Autonomic Jump

Look like it’s possible use whichever external library available on Ocaml

Pls install a big_int library like zarith using opam, you should be able to use the library inside your code

Let me know if you have any problem, I’m working in give support to this in our pipeline

Thank you Luis! Actually I was able to installed it. However don’t know how to ‘activate it’ in my environment. I found that can be compiled like: ocamlc -I +zarith -o file -pp "refmt -p ml" -impl But no idea how to implemented in the IDE compiler.

This shows the installed packages:


you can use this template GitHub - esy-ocaml/hello-reason: an example esy-powered Reason project

You will find a file in lib/dune inside you need to add the library zarith and change ocaml version

 (name lib)
  (-w -40 -w +26))
 (public_name hello-reason)
 (libraries pastel.lib zarith))

the in the file package.json you will find a section of dependencies, add zarith

  "dependencies": {
    "@opam/dune": ">=2.6",
    "@reason-native/console": "*",
    "@reason-native/pastel": "*",
    "@esy-ocaml/reason": ">= 3.6.0 < 4.0.0",
    "ocaml": "~4.11.0",
    "@opam/zarith": ">=1.12"

You can install esy with this command nix-env -iA nixpkgs.nodePackages.esy if you already installed Nix

Running esy command you will get compiled your file, I run this example code

open Big_int_Z;
let data : string = "121212121212121212312312312312312312312341231231231341341121212121213";
let first : big_int = big_int_of_string (data);
let second : big_int =  big_int_of_int (12);
let solution : big_int = add_big_int (first, second)
let convertion = string_of_big_int(solution);
Printf.printf("%s", convertion);
1 Like

Additional data
Support ReasonML with nix requiere to install these packages

- ocaml
- reason
- ocamlPackages.findlib
- ocamlPackages.zarith

After that it’s necessary set the following env variables where envZarith is the path to the Zarith nix pkg

export OCAMLPATH="${envZarith}/lib/ocaml/4.12.0/site-lib/"
export CAML_LD_LIBRARY_PATH="${envZarith}/lib/ocaml/4.12.0/site-lib/stublibs"

to compile with zarith library you need to run like this

ocamlfind ocamlc -package zarith -linkpkg -o test -pp "refmt -p ml" -impl

1 Like

Thank you very much Luis! The information was really helpful. I tried with the mentioned “bundled” package Num, and it compile with success.

I’m afraid to said that I don’t understand really well how Nix works. So, I’m ussing the VSCode OCaml Platform with a default switch installed via opam (in that switch I installed all the required packages to run the VSCode extension).

Here’s a screeshot of my environment:

The compiler code is: ocamlfind ocamlc -package num -linkpkg -o test -pp "refmt -p ml" -impl

It works perfect!!! :star_struck:

However, this error remains in the IDE:
It’s not fatal, because the code compile, but is annoying and get more complex to debug it.

I keep making progress, but would be wonderful to avoid the IDE error.

Thank for the support @uneasy-ruler