Version française
Home     About     Download     Resources     Contact us    

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

Browse thread
Re: [Caml-list] Runtime overflow and what to do
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-10-13 (10:19)
From: Pierre Weis <pierre.weis@i...>
Subject: Re: [Caml-list] Runtime overflow and what to do
> > So it is not easy, perhaps even impossible if the processor doesn't set a
> > flag .
> It is possible, but slow and not pretty!

I must precise that even if the code to implement arithmetics with
overflow checks can be considered as ``not pretty'', its usage is
absolutely easy and transparent in Caml: just write a specialized
module for arithmetics with overflow checks (say ``Cautious_arith'')
that redefines ( + ), ( - ), ( * ), ( / ), min, etc, along the lines
sketched by Xavier for addition (by the way, writing such a module is
a very pleasant home exercise); once you have written the
Cautious_arith module, write your application code as usual.

Now, if you want overflow checks just add

open Cautious_arith

at the beginning of your module and recompile.

If you changed your mind, and want to recover the normal speed of
integer arithmetic operations, just remove the open directive and

This is an elegant and clean application of very basic operators
redefinition that not so many programming languages offer.

Pierre Weis

INRIA, Projet Cristal,,

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: