News for hackers. Stuff that matters.
Re:A convenient untruth: Array notation in C is a lie by pasquinelli on Thursday December 22, 2016 @11:17AM (#13238213)
Right, in a language with dependent types there is a type-level difference between int[5] and int[7], but c is not such a language, therefore using a syntax that encourages the mistaken notion that there is a type-level difference between int[5] and int[7] would be misleading.
Re:A convenient untruth: Array notation in C is a lie by kibwen on Thursday December 22, 2016 @08:13PM (#13242014)
A language doesn't need dependent types to make fixed-size arrays of differing size count as incompatible types. Rust does this, for example:

  // error: expected an array with a fixed size of 5 
  // elements, found one with 7 elements
  let x: [i32; 5] = [1,2,3,4,5,6,7];
Re:A convenient untruth: Array notation in C is a lie by pasquinelli on Saturday December 24, 2016 @12:41AM (#13248752)
i don't know rust, but i read a bit about fixed size arrays in it and the fact that 32 is the largest fixed size array makes me suspicious that it works like a pair. you can do this without depending on a value, because the length is encoded in the type.

like, you can have a type (a, b), and b can, of course, be of type (a, b), b again having type (a, b), and so on. then you always carry around the length encoded in the type, and it can be checked like above.

ghc has a limit on tuple sizes, and haskell makes no type distinction between [a] based on the number of elements in it, and it isn't dependently typed.

but again i don't know rust.

Re:A convenient untruth: Array notation in C is a lie by kibwen on Saturday December 24, 2016 @01:09AM (#13248828)

  > i read a bit about fixed size arrays in it and the fact 
  > that 32 is the largest fixed size array
This is exceptionally mistaken, where did you read it? Arrays in Rust top out at the maximum value of a platform-sized pointer, which is either 2^32 or 2^64 depending on platform.
Re:A convenient untruth: Array notation in C is a lie by pasquinelli on Saturday December 24, 2016 @06:02PM (#13252001)
"Arrays of sizes from 0 to 32 (inclusive) implement the following traits if the element type allows it:

Clone (only if T: Copy) Debug IntoIterator (implemented for &[T; N] and &mut [T; N]) PartialEq, PartialOrd, Eq, Ord Hash AsRef, AsMut Borrow, BorrowMut Default This limitation on the size N exists because Rust does not yet support code that is generic over the size of an array type. [Foo; 3] and [Bar; 3] are instances of same generic type [T; 3], but [Foo; 3] and [Foo; 5] are entirely different types. As a stopgap, trait implementations are statically generated up to size 32."

from the rust docs. https://doc.rust-lang.org/std/primitive.array.html

i sort of leapt to the conclusion that these traits couldn't be implemented because generically because the type system requires them to be implemented for each size of N, and they provide the first 32 as a nicety. the similarity to the situation with tuples in haskell, (http://stackoverflow.com/questions/2978389/haskell-tuple-siz...), and the fact that rust doesn't have dependent types and so a type couldn't depend on a value, and i just kind of guessed at a possible reason.

Re:A convenient untruth: Array notation in C is a lie by kibwen on Sunday December 25, 2016 @02:00AM (#13253299)
Ah I see, yes the explanation there is correct. The types exist up to ginormous sizes, but the standard library only implements certain convenience traits for certain sizes (though using newtypes, you can implement those traits yourself for any array size you want). The specific feature we're lacking is type-level numerals, which is on the way towards but not anywhere close to a dependent type system AIUI.
Re:A convenient untruth: Array notation in C is a lie by Nullabillity on Thursday December 22, 2016 @07:45PM (#13241864)
Saying int[5] and int[7] are the same type because the compiler doesn't enforce the difference is like saying JavaScript is untyped because there is no compiler to enforce types at all.

Regardless of what the spec or the compiler says, you the programmer absolutely need to treat them separately. Especially in a language like C, where arrays aren't even self-describing at runtime.

Re:A convenient untruth: Array notation in C is a lie by pasquinelli on Saturday December 24, 2016 @12:32AM (#13248722)
no it isn't. javascript has types; they exist only at runtime, but they're there. it's patently false to say it's untyped. but type differences codify certain classes of differences, and it really isn't that crazy or unusual to say that the length of a vector, array, list, whatever you want to call it, isn't a difference of type. to say that there's a type difference even if the type checker disagrees just means you and the type checker are using different type systems.
Re:A convenient untruth: Array notation in C is a lie by Vogtinator on Thursday December 22, 2016 @02:39PM (#13239711)
There is a small type difference in C, sizeof() of those two types is different.