Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
recompile!

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

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/


-------------------
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