ocaml - Error: Reference to undefined global `Num' -


i'm trying use num module in ocaml (bignums , big fractions). things seem working, while others seem not to, , i'm not able generate single, complete example. instance:

# num.int(234);; - : num.num = num.int 234 # num.mult_num;; characters -1--1:   num.mult_num;; error: reference undefined global `num' 

may ask simple example of multiplying 2 bignums?

the reference num here.

if toplevel launched, can dynamically load library:

# #load "nums.cma";; # num.mult_num;; - : num.num -> num.num -> num.num = <fun> 

another possibility (which work third party libraries , manage paths , dependencies you) use ocamlfind. this, issue

#use "topfind";; 

(or better put in ~/.ocamlinit file). load library, do

# #require "num";; /usr/lib/ocaml/nums.cma: loaded /home/user/.opam/system/lib/num-top: added search path /home/user/.opam/system/lib/num-top/num_top.cma: loaded /home/user/.opam/system/lib/num: added search path 

(if ocamlfind — hence topfind — not available, install using opam.)

here example of multiplication:

# num.(num_of_int 30 */ num_of_int 1234);; - : num.num = num.int 37020 

the construction num.(e) shorthand let open num in e , makes possible use num functions without prefix in e. here definition of factorial:

# let rec fac n =     let open num in     if n =/ int 0 int 1 else n */ fac (n -/  int 1);; val fac : num.num -> num.num = <fun> 

you can try with

# fac num.(int 100);; - : num.num = num.big_int <abstr> 

if used #require, installs pretty printer num values previous interaction looks like:

# fac num.(int 100);; - : num.num = <num 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000> 

which easier read!


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -