Working with Big Integers?


There is a way to work with Big integers?

I need to make operations with big integers as this one

I could use Ocaml libraries or something like that if possible, it seems that the Num module of ocaml could help me but I don’t know if it is possible to add modules external to Reason to my code

I use this command to compile my code ocamlc -o test -pp "refmt -p ml" -impl and using Nixpkgs to install dependencies


Answered in ReasonML Discord,

Please link if posting in multiple forums.


Hi @yawaramin thx for your help

As additional info
Support ReasonML with Nix (without use ESY) require to install these packages from Nixpkgs

  • 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 (from /nix/store)

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

To support this in a pipeline I use a framework called Makes that simplify a lot the work

To support with ESY hello-world template
You will find a file in lib/dune inside you need to add the library Zarith

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

then 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"