www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: grep

reply terranium <spam here.lot> writes:
Dee Girl Wrote:

 Your example compiles but it was so good if it did not. Modifiable arrays
should never be covariant!

Compiles and works? There is no problem with covariance, it just needs runtime typechecks for assignment.
May 10 2008
parent reply terranium <spam here.lot> writes:
terranium Wrote:

 Dee Girl Wrote:
 
 Your example compiles but it was so good if it did not. Modifiable arrays
should never be covariant!

Compiles and works? There is no problem with covariance, it just needs runtime typechecks for assignment.

The problem is array (unlike java and .Net) is a primitive type, so it doesn't have TypeInfo and doesn't know what it's supposed to contain, so it can't do typechecks.
May 10 2008
parent reply Dee Girl <deegirl noreply.com> writes:
terranium Wrote:

 terranium Wrote:
 
 Dee Girl Wrote:
 
 Your example compiles but it was so good if it did not. Modifiable arrays
should never be covariant!

Compiles and works? There is no problem with covariance, it just needs runtime typechecks for assignment.

The problem is array (unlike java and .Net) is a primitive type, so it doesn't have TypeInfo and doesn't know what it's supposed to contain, so it can't do typechecks.

Maybe check insertion could be arranged by the compiler. Java does that. But it is generally better to detect type errors earlier. D has const so not much expressive is lost. Dee Girl
May 10 2008
parent reply terranium <spam here.lot> writes:
Dee Girl Wrote:

 Maybe check insertion could be arranged by the compiler. Java does that. But
it is generally better to detect type errors earlier. D has const so not much
expressive is lost. Dee Girl

Typecheck can't be arranged out of nothing. Java and CLR can do a typecheck because array is an object there, a complex object, arrays in D are just slices - pairs of pointer and length. There is no way to do a typecheck, because there is no type to check against.
May 10 2008
parent Dee Girl <deegirl noreply.com> writes:
terranium Wrote:

 Dee Girl Wrote:
 
 Maybe check insertion could be arranged by the compiler. Java does that. But
it is generally better to detect type errors earlier. D has const so not much
expressive is lost. Dee Girl

Typecheck can't be arranged out of nothing. Java and CLR can do a typecheck because array is an object there, a complex object, arrays in D are just slices - pairs of pointer and length. There is no way to do a typecheck, because there is no type to check against.

I finally understood, thank you. Your explanation is another good argument: that covariance of modifiable arrays should be statically disallowed. Dee Girl
May 10 2008