Reading about D: few questions
Timon Gehr
timon.gehr at gmx.ch
Sat Dec 24 02:33:32 PST 2011
On 12/24/2011 02:02 AM, Jonathan M Davis wrote:
> The core problem for a number of these situations is how types are handled
> with regards to expressions. In an expression such as
>
> char[] arr = s ~ '.';
>
> the type of the value being assigned is determined _before_ the assignment is
> done. So, even though in theory the compiler could make it work, it doesn't,
> because by the time it's looking at the type being assigned to, it's too late.
> There would need to be a fundamental change in how the language functions in
> order to fix issues like this.
Examples of resolved issues like this:
int[] foo()pure;
immutable(int)[] x = foo;
>
> pure can do it when it can not because it's able to look at what the return
> type is and changing the result of the expression accordingly but because it
> has guarantees which make it so that it knows that the return value could be
> converted to any level of constness and still be valid. The types used in the
> expressions internally are generally irrelevant.
>
> So, while I completely agree that it would be an improvement if the compiler
> did a better job with implicit conversion when it could theoretically be done,
> I'm not sure how much of that we're actually going to end up seeing simply
> because of how the language and type system works in terms of the order of
> evaluation.
>
> - Jonathan M Davis
I don't think this is very hard to get working.
More information about the Digitalmars-d-learn
mailing list