On 11/29/10 7:52 PM, Michel Fortin wrote:
On 2010-11-29 14:03:27 -0500, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> said:

For instance, here's a tricky question: should Unqual!(const C) give you
a const(C), a Rebindable!(const C), or simply C?

C.

Now, what should
const(Unqual!(immutable C)) give you?

const(C).

As I thought.

Now consider this generic code that uses Unqual:

T[] giveMeASortedArray(alias Predicate, T)(T[] t) {
// creating new array of the same length but with assignable elements
auto copy = new Unqual!(typeof(t[0]))[t.length];

// using a loop because copy[] = t[] doesn't enforce const properly!
foreach (index, value; t)
copy[index] = value;

// sorting the copy
sort!(Predicate)(copy);
return copy;
}

The above algorithm will work for types like const(int*), but it breaks
if T is const(C) and C is a class. So it seems we'll need a special
cases for generic algorithms to work for classes. That's what I meant
when I say Rebindable is a fragile solution. It works in most cases, but
it breaks in some others, mostly when you want to be generic.

So here's the challenge for you Andrei:
[snip]

I agree that the problem is difficult but disagree with the angle. This is not the challenge, and it is not only mine to take. To the extent we're interested in making D a successful language, we're all on the same boat, so the challenge belongs to us all.

Adding a new type constructor to the language or generally a new feature is always possible, but has a high cost. Half of the community throws their hand in the air with each new feature, and the other half throws them in the air for each feature that could have been. The key is to navigate such that as many good designs are expressible as easily as possible.

The real challenge is to solve the problem within the global set of constraints we have, not to prove that a language feature would solve it. I know a language feature would take care of the issue, the same way money would take care of buying a nice house. The challenge is to have a nice house when money _is_ limited.


Andrei

Reply via email to