Working with Big Integers?


#1

Hi,
There is a way to work with Big integers?

I need to make operations with big integers as this one
2005386240811006492510206908835874977464399827995998174235015291258133373258958037573585627

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 test.re and using Nixpkgs to install dependencies


#2

Answered in ReasonML Discord, https://discord.com/channels/235176658175262720/235176658175262720/886436140389900288

Please link if posting in multiple forums.


#3

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 test.re

To support this in a pipeline I use a framework called Makes that simplify a lot the work https://github.com/fluidattacks/makes

To support with ESY hello-world template https://github.com/esy-ocaml/hello-reason
You will find a file in lib/dune inside you need to add the library Zarith

(library
 (name lib)
 (flags
  (-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"
  },