[Haskell-cafe] Specify array or list size?
Thomas Davie
tom.davie at gmail.com
Sat May 7 15:41:35 EDT 2005
On May 7, 2005, at 8:31 PM, David Roundy wrote:
> On Sat, May 07, 2005 at 08:20:15PM +0100, Thomas Davie wrote:
>
>> On May 7, 2005, at 8:07 PM, Marcin 'Qrczak' Kowalczyk wrote:
>>
>>> The size is taken into account when such array type is an element of
>>> another array, and by sizeof.
>>>
>>> int (*p)[50]; /* p may legally point only to arrays of 50 ints
>>> each */
>>> ++p; /* p is assumed to point into an array, and is moved by one
>>> element, i.e. by 50 ints */
>>>
>>
>> I'm not sure what you're trying to prove by saying that... There is
>> still no type information that says that the contents of p are an
>> array of 50 elements... I can still attempt to access element 51 and
>> get a runtime memory error. The type of p is still int**, not
>> "pointer to array of 50 ints"
>>
>
> No, int (*p)[50] is a multidimensional array, one of the most useless
> concepts in C, and is equivalent to int p[50][] (or is it p[][50]... I
> always get my matrix subscripts messed up).
>
> In a multi-dimensional array, all the dimensions but the first (or
> last?)
> are fixed in size. Unfortunately, these are fixed at compile time, so
> there's no way to write a function that can act upon multidimensional
> arrays of arbitrary size. So we get the joy of writing terms like m
> [i+n*j]
> to deal with matrices...
:o It appears I have grossly underestimated how much C checks at
compile time... I still feel all warm and cuddly in the everything
checked world of Haskell though. And with that... I wonder, is this
topic perhaps diverging from discussing how to get list sizes checked
with Haskell's type checker and moving onto something relatively
irrelevant.
Bob
More information about the Haskell-Cafe
mailing list