Re: Array Indexing

1992-03-02 Thread Kevin Hammond

> Currently, the report says nothing about whether an instance
> of Ix should perform bounds checking, or whether this is done
> automatically by the implementation.
>
> My proposal was to say that it should be in the instance
> declaration, which gives the user a variety of options as to
> how to implement bounds checking, including not at all.
>
> The alternative is to say that the implementation itself
> will perform a bounds check, which constrains the implementation
> but guarantees that it always happens.
>
> On pondering this after Joe's question, I find I don't have
> a strong feeling in either direction.  But we ought to specify
> which (so that a careful programmer knows whether to include
> bounds checks, or whether the system will provide).

I think it is specified already by the semantics of "array".  The fact
that an error results for out-of-bounds indexes implies that a bounds
check must be performed for each array access [in an implementation
without bounds checking, an unexpected defined value could be returned,
which would be incorrect].  As Phil points out, this isn't the most
desirable implementation -- checking on index generation could be
rather more efficient (because indexes may be shared).  Given the
serious lack of time, maybe we should just leave it as is?

Kevin





Re: Array Indexing

1992-03-02 Thread Philip Wadler

Joe asks for clarification.

Currently, the report says nothing about whether an instance
of Ix should perform bounds checking, or whether this is done
automatically by the implementation.

My proposal was to say that it should be in the instance
declaration, which gives the user a variety of options as to
how to implement bounds checking, including not at all.

The alternative is to say that the implementation itself
will perform a bounds check, which constrains the implementation
but guarantees that it always happens.

On pondering this after Joe's question, I find I don't have
a strong feeling in either direction.  But we ought to specify
which (so that a careful programmer knows whether to include
bounds checks, or whether the system will provide).

Cheers,  -- P





Re: Array Indexing

1992-03-02 Thread Philip Wadler

! It is the responsibility of the programmer to enforce bounds
! checking when required in non-derived instances of class @Ix@.
! An implementation is not required to check that an index
! lies within the bounds of an array when accessing that array.

The above is fine by me, but here is a more concise wording, which may
do as well.

! It is the responsibility of the programmer to enforce bounds
! checking in non-derived instances of class @Ix@, if it is desired.

Cheers,  -- P




Re: Array Indexing

1992-03-02 Thread jhf

| ! It is the responsibility of the programmer to enforce bounds
| ! checking when required in non-derived instances of class @Ix@.
| ! An implementation is not required to check that an index
| ! lies within the bounds of an array when accessing that array.
|
| The above is fine by me, but here is a more concise wording, which may
| do as well.
|
| ! It is the responsibility of the programmer to enforce bounds
| ! checking in non-derived instances of class @Ix@, if it is desired.
|
| Cheers,  -- P

This sounds fine to me.   Maybe I should put bounds checks in the
Ix instance declarations for Integer, Int, and Char in PreludeCore.

--Joe