caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: jfh@cs.brown.edu
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] More or bignums/ints
Date: Sat, 12 Jun 2004 09:09:18 +0900 (JST)	[thread overview]
Message-ID: <20040612.090918.74661009.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <20040611193818.0A43457251@twix.cs.brown.edu>

From: "John Hughes" <jfh@cs.brown.edu>
> 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


  reply	other threads:[~2004-06-12  0:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-11 19:38 John Hughes
2004-06-12  0:09 ` Jacques Garrigue [this message]
2004-06-14 15:37 ` Brian Hurt
2004-06-14 16:17   ` Andreas Rossberg
2004-06-14 15:55 ` Xavier Leroy
2004-06-15 22:45   ` Manos Renieris
2004-06-15 20:26 ` Brian Hurt
2004-06-15 20:36   ` Brian Hurt
2004-06-23 10:50   ` John Hughes
2004-06-23 14:51     ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040612.090918.74661009.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=jfh@cs.brown.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).