From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA10608; Sat, 12 Jun 2004 02:09:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA10522 for ; Sat, 12 Jun 2004 02:09:09 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i5C096SH024872 for ; Sat, 12 Jun 2004 02:09:07 +0200 Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id JAA02314; Sat, 12 Jun 2004 09:09:02 +0900 (JST) Date: Sat, 12 Jun 2004 09:09:18 +0900 (JST) Message-Id: <20040612.090918.74661009.garrigue@kurims.kyoto-u.ac.jp> To: jfh@cs.brown.edu Cc: caml-list@inria.fr Subject: Re: [Caml-list] More or bignums/ints From: Jacques Garrigue In-Reply-To: <20040611193818.0A43457251@twix.cs.brown.edu> References: <20040611193818.0A43457251@twix.cs.brown.edu> X-Mailer: Mew version 4.0.64 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 40CA49A2.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 bignums:01 jacques:01 bignums:01 pervasives:01 beginners:01 debugger:01 dialect:01 ocamlrun:01 overflows:01 jacques:01 ints:01 ints:01 ocaml:01 caml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: "John Hughes" > So the questions are > > 1. Is there a way to catch overflow exceptions within an entire > computation? Not that I know of. > 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) No. Old Caml had (a), but this is more than 10 years ago. Note however that you may redefine operators if you want to: exception Int_overflow let (+) a b = let c = Pervasives.(+) a b in if a < 0 && b < 0 && c >= 0 || a > 0 && b > 0 && c <= 0 then raise Int_overflow; c This is going to be pretty slow, but if this is for beginners this shouldn't matter too much. And it won't change the behaviour of other operations in the library, but you don't want to: they may depend on the rollover behaviour. > 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"? I don't know, but it should be possible to hack ocamlrun to check for overflows. Combined with C primitives, you could also set whether an exception should be raise or not. A bit more painful than the above approach, but this should run faster. Jacques Garrigue ------------------- 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