This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

[Caml-list] More or bignums/ints
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2004-06-11 (19:38) From: John Hughes Subject: [Caml-list] More or bignums/ints
```I've read the May interchange in CWN that started with the question

> I have made a web search to understand which kind of support for
> bignums is available for OCaml...

and found it interesting. I'll be teaching a few weeks of ML as part
of a first-year course at Brown University, and we've used SML in
previous years. SML/NJ works OK, but we'd like a debugger, so I've
looked at OCaml as a possible alternative. I was a little depressed
to find (by trial and error) that "int" doesn't mean "integer" but
rather "element of Z/nZ for some very large n, represented with
integer notation, including negative signs."

I think I can live with this if only there's some way to write
something like this (pseudo-ML/Java):

fun fact(0) = 1
| fact(n) = try {
n * fact(n-1)
}
catch (IntegerOverflow e) ...

What I don't think I can bear is to use the sorts of "bignum"-like
libraries that make me write things like

y = x bigadd big-unit

to mean

y = x + 1

because our students will actually be writing some code that has
a good deal of arithmetic in it.

---

So the questions are

1. Is there a way to catch overflow exceptions within an entire
computation?
2. Is there a way to tell OCaml that ints really are either
(a) bignums or
(b) overflow-protected ints (as in SML/NJ, for instance)

Perhaps the implicit third question is

3. Is there a reasonable debugger for some dialect of ML that has
what I might call "protected integers"?

Thanks very much in advance.

-John Hughes

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

```