caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Statically detecting arrays bound exceptions ?? (was: Universal Serializer)
@ 2002-07-17  6:19 Johan Baltié
  2002-07-17  6:46 ` Jacques Garrigue
  0 siblings, 1 reply; 12+ messages in thread
From: Johan Baltié @ 2002-07-17  6:19 UTC (permalink / raw)
  To: caml-list

Ok as there were the two same comments on my post I do a single answer.

Here my first post:

>> What about defining type that are subranges of int ?
>> à la ADA...


Here the comments:
-----
>Then how do you make sure that the result of an arithmetic expression is
>still within that sub-range? For example, m.( i + j ) ?
>
>Cheers,
>Hao-yang Wang

-----

>as i said to john skaller, won't you then get index incrementation exceptions ?
>anyway, it's a trade-off.
>
>-- 
>Berke
>mayur_naik@my-deja.com writes:

-----

Now, as I am not an ADA guru I just show you my source:

http://groups.google.com/groups?hl=fr&lr=&ie=UTF-8&oe=UTF-8&frame=right&th=5c68b368acf1e99&seekm=00-04-194%40comp.compilers#link5

------------- BEGIN OF FOLLOWUP -------------

> Does any language or any machine provide some mechanism to:
>
> 1. index an array without checking its bounds
> 2. throw an exception if the index was actually out of range
> 3. allow the programmer to catch and handle the exception rather than
>    terminate the program

Well, Ada does. The strong typing gives information to the compiler for it to
deduce when range checking is not needed:

declare
  subtype Index is Integer range 1..10;
  type Arr is array (Index) of Integer;
  a : Arr;
  element : Integer;
  j : Index := 1;
  k : Integer := 11;
begin
  for i in a'Range loop
    element := a(i); -- no range checking needed, i is in range by definition
  end loop;
  a(j); -- range checking not needed, j is within Index by definition
  a(k); -- range checking needed due possibility of k being outside of Index
exception
  when Constraint_Error =>
     -- process the out-of-range error from a(k)
end;

--
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
blaak@infomatch.com                            The Rhythm has my soul.

------------- END OF FOLLOWUP -------------

IMHO, the use of subtypes help to avoid a lot of bound check, maybe not all of
them, but I do not think that eliminating *all* the bounds check is useful.

Another point is that using subranges you're not allowed to do many errors as
when you are using bare int.

Ciao

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


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [Caml-list] productivity improvement
@ 2002-07-08 19:53 Oleg
       [not found] ` <15657.61603.221054.289184@spike.artisan.com>
  0 siblings, 1 reply; 12+ messages in thread
From: Oleg @ 2002-07-08 19:53 UTC (permalink / raw)
  To: caml-list

Hi

As part of learning O'Caml I was rewriting small personal utility programs 
from C++ to O'Caml and I have not seen any productivity improvement so far. 
Possibly, this is because I essentially use the same imperative style or 
because my knowledge of O'Caml is rudimental or because there is no 
productivity enhancement, at least for the programs I was translating or for 
small programs in general.

What are the _simplest_ examples that demonstrate considerable (> 2:1) O'Caml 
vs C++ productivity improvement (in terms of program size) and where can I 
find them?

Thanks
Oleg

P.S. Just trying to stay motivated.
-------------------
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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2002-07-20 13:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-17  6:19 [Caml-list] Statically detecting arrays bound exceptions ?? (was: Universal Serializer) Johan Baltié
2002-07-17  6:46 ` Jacques Garrigue
2002-07-17  7:14   ` Johan Baltié
2002-07-17  7:32     ` Jacques Garrigue
2002-07-17  7:53       ` [Caml-list] Sub{range,type} (was: Statically detecting arrays bound exceptions ??) Johan Baltié
  -- strict thread matches above, loose matches on Subject: below --
2002-07-08 19:53 [Caml-list] productivity improvement Oleg
     [not found] ` <15657.61603.221054.289184@spike.artisan.com>
2002-07-09  4:43   ` [Caml-list] Universal Serializer (was: productivity improvement) Oleg
2002-07-09  7:59     ` Nicolas Cannasse
2002-07-10 16:06       ` John Max Skaller
2002-07-10 22:29         ` Michael Vanier
2002-07-12 12:41           ` John Max Skaller
2002-07-14 12:25             ` [Caml-list] Statically detecting arrays bound exceptions ?? (was: Universal Serializer) Berke Durak
2002-07-14 13:24               ` Alessandro Baretta
2002-07-15  8:23                 ` Xavier Leroy
2002-07-15  8:39                 ` Noel Welsh
2002-07-15 21:22                   ` Oleg
2002-07-15 22:44                     ` Michael Vanier
2002-07-16  6:43                     ` Florian Hars

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