[M3devel] ARRAY OF ARRAY (Re: A bizarre language quirk)

Hendrik Boom hendrik at topoi.pooq.com
Sat Mar 24 20:10:55 CET 2018


On Sat, Mar 24, 2018 at 07:49:30PM +0100, Henning Thielemann wrote:
> 
> On Fri, 23 Mar 2018, Rodney M. Bates wrote:
> 
> >On 03/21/2018 02:57 PM, Henning Thielemann wrote:
> >>
> >>On Wed, 21 Mar 2018, Rodney M. Bates wrote:
> >>
> >>>Modula3, 2.6.3 (Designators), concerning subscripting says:
> >>>
> >>>An expression of the form a[i_1, ..., i_n] is shorthand for
> >>>a[i_1]...[i_n].
> >>
> >>I think I wrote earlier about this shorthand ...
> >>
> >>I found the following problem:
> >>
> >>ARRAY OF ARRAY OF Something
> >>
> >>is syntactically not quite a 2D-array since as it is written it suggests
> >>that the sub-arrays may have different sizes.
> >
> >It never occurred to me that this syntax could suggest it could be a
> >ragged array, probably because I was already familiar with the (fixed)
> >array-of-array concept being truly 2D in Pascal and Modula2.
> 
> I did not have problems in understanding the Modula-3 report, instead I
> consider it a flaw in the syntax and it has practical consequences. Why can
> I choose in ARRAY OF ARRAY only the size of the outer array freely and the
> sizes of the inner arrays are constrained? Where is the composability of
> type constructors? And what is the size of the inner arrays if there are no
> inner arrays? What else would be the type of a ragged array, if not ARRAY OF
> ARRAY OF T?
> 
> In Haskell "Array Int (Array Int a)" would be actually a ragged array (in
> Haskell all objects are actually pointers to objects) and a rectangular
> 2D-array would have the type "Array (Int,Int) a".

Algol 68 has n-dimensional arrays, for fixed n.  That is, the number of 
subscripts is fixed by the program at compile time.  THey are rectangular.

The size of arrays are fixed at allocation time.  They are not part of 
the type of the array.  It is possible to have zero by n arrays, and n 
by zero arrays.

There is nothing preventing an array from having other arrays as 
components.  Those other arrays will have their own rectangular storage 
space elsewhere.

Arrays can be declared to be flexible, in which case the flexibility is 
part of the array type and the actual array can change its size at run 
time..

There's an obscure corner of the semantics involving flexible arrays 
whose elements are inflexible arrays.  The language definition 
describes a ghost element to remember the size of the inner 
arrays.  It's not clear to me that this is anything but pedantry.

-- hendrik


More information about the M3devel mailing list