[Caml-list] Re: How public is Num.Nat

2010-07-10 Thread Jim Pryor
Hi I'm looking into wrapping the Nat module from the Num package. I
can't find any documentation for it, but the source + a bit of guesswork makes
it somewhat accessible.

However, superficially at least it looks like this library enables
arbitrary getting/setting of bytes in the program's heap, with no
bounds checking. Please tell me it's not so!

$ ocaml dynlink.cma
Objective Caml version 3.12.0+beta1

# #require num;;
# open Nat;;
# let nx = nat_of_int 3;;
# let dump () = List.map (fun x - nth_digit_nat nx x) [0;1;2;3;4;5;6;7;8];;
# dump ();;
- : int list =
[3; 1024; 1; 3074; 139752628822496; 1; 139752628800520; 1024; 1]
# set_digit_nat nx 6 111999111; nth_digit_nat nx 6;;
- : int = 111999111
# dump();;
- : int list = [3; 1024; 1; 3074; 139752628822496; 1; 111999111; 1024; 1]


I found this old message in the mailing list, but it seems to have gotten no 
answer:

On Fri, Nov 07, 2008 at 10:33:41AM +0100, Andrej Bauer wrote:
 The Nat module in the Num library is not documented in the official
 documentation, but is documented in the 1992 tech report by Valérie
 Ménissier-Morain. I would ilke to use Ocaml-only library for big
 integers which has bit shifting operations. Big_int does not, but Nat
 does. Is Nat stable and safe to use by people who are neither
 French, nor at INRIA, nor are they Ocaml developers?
 
 Before someone tells me I should use GMP and/or MPFR: I am already
 using them, I am just rewriting a piece of code so that it can be
 optionally compiled with pure ocaml.

-- 
Jim Pryor
prof...@jimpryor.net

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] Re: How public is Num.Nat

2010-07-10 Thread Jim Pryor
On Sat, Jul 10, 2010 at 08:42:28AM -0400, Jim Pryor wrote:
 Hi I'm looking into wrapping the Nat module from the Num package. I
 can't find any documentation for it, but the source + a bit of guesswork makes
 it somewhat accessible.
 
 However, superficially at least it looks like this library enables
 arbitrary getting/setting of bytes in the program's heap, with no
 bounds checking. Please tell me it's not so!

I found the documentation from 1992 here:
ftp://ftp.inria.fr/INRIA/publication/publi-pdf/RT/RT-0141.pdf

Not quite the same location listed in Ch 22 of the ref manual, but not
too far off, either. It seems that what I observed is indeed the documented
behavior of the Nat module. The Big_int and Num modules hide that
nastiness away.

-- 
Jim Pryor
prof...@jimpryor.net

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs