From: Alain Frisch <Alain.Frisch@ens.fr>
To: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
Cc: skaller@users.sourceforge.net, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: OCAML Downcasting?
Date: Wed, 22 Sep 2004 14:03:36 +0200 (MEST) [thread overview]
Message-ID: <Pine.SOL.4.44.0409221352170.28956-100000@clipper.ens.fr> (raw)
In-Reply-To: <87d60eizlh.fsf@qrnik.zagroda>
On Wed, 22 Sep 2004, Marcin 'Qrczak' Kowalczyk wrote:
> This is the catch: "where possible". I would add: "where practical";
> sometimes the cost outweights the benefits. For example static
> detection of possible division by 0 would be impractical. You would
> have to either embed a proof checker in the language in order to be
> able to convince the compiler that the number can't be 0, or not use
> exceptions at all and have all partial functions return a result in
> "option" type or similar, with manual propagation of errors.
You don't necessarily have to use a proof checker. What about using a type
system, or a(nother kind of) static analysis ? E.g. detection of division
by 0 can be done with interval arithmetic, and it might work well in
practice.
> And guess what? No language I know checks division by 0 statically
> (except proof checkers, but they are not suitable for writing big
> programs - too much work).
CDuce version 0.2.1+1
# fun (x : Int) : Int = 1 div x;;
Warning at chars 22-29:
This operator may fail
- : Int -> Int = <fun>
# fun (x : 0--*) : Int = 1 div x;;
Warning at chars 23-30:
This operator may fail
- : 0--* -> Int = <fun>
# fun (x : 1--*) : Int = 1 div x;;
- : 1--* -> Int = <fun>
# fun (x : 1--*) : Int = 1 div (x + x);;
- : 1--* -> Int = <fun>
# fun (x : 1--*) : Int = 1 div (x - x + x);;
Warning at chars 23-40:
This operator may fail
- : 1--* -> Int = <fun>
(type 1--* means: "positive integers")
To get rid of warning (or compile-time error) when the type system is not
precise enough (the last example above), you can always do an
explicit check:
# fun (x : 1--*) : Int =
match x - x + x with
| y & (1--*) -> 1 div y
| _ -> raise "Bla";;
- : 1--* -> Int = <fun>
-- Alain
-------------------
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
next prev parent reply other threads:[~2004-09-22 12:03 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <ci7tcf$qqf$1@wolfberry.srv.cs.cmu.edu>
[not found] ` <ci9ggm$i6p$1@wolfberry.srv.cs.cmu.edu>
2004-09-21 8:03 ` Jacques GARRIGUE
2004-09-21 8:43 ` Damien Pous
2004-09-21 9:15 ` Jacques GARRIGUE
2004-09-21 9:29 ` skaller
2004-09-21 9:49 ` Jacques GARRIGUE
2004-09-21 9:34 ` Stefano Zacchiroli
2004-09-21 9:56 ` Jacques GARRIGUE
2004-09-21 19:27 ` Michael Vanier
2004-09-21 21:38 ` Brian Hurt
2004-09-21 22:06 ` Michael Vanier
2004-09-21 22:32 ` Brian Hurt
2004-09-22 1:04 ` skaller
2004-09-21 22:20 ` Marcin 'Qrczak' Kowalczyk
2004-09-22 2:26 ` skaller
2004-09-22 6:31 ` Marcin 'Qrczak' Kowalczyk
2004-09-22 9:03 ` sejourne_kevin
2004-09-22 10:29 ` Richard Jones
2004-09-22 18:39 ` Brian Hurt
2004-09-22 10:50 ` skaller
2004-09-22 12:03 ` Alain Frisch [this message]
2004-09-22 12:50 ` Cláudio Valente
2004-09-22 13:15 ` Marcin 'Qrczak' Kowalczyk
2004-09-22 15:50 ` skaller
2004-09-22 18:42 ` Brian Hurt
2004-09-22 18:44 ` Marcin 'Qrczak' Kowalczyk
2004-09-22 19:18 ` Brian Hurt
2004-09-22 0:50 ` skaller
2004-09-22 1:30 ` Jacques GARRIGUE
2004-09-22 2:59 ` 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=Pine.SOL.4.44.0409221352170.28956-100000@clipper.ens.fr \
--to=alain.frisch@ens.fr \
--cc=caml-list@inria.fr \
--cc=qrczak@knm.org.pl \
--cc=skaller@users.sourceforge.net \
/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