Type inference and overloaded functions

Timothee Cour thelastmammoth at gmail.com
Wed Dec 11 18:03:35 PST 2013


On Wed, Dec 11, 2013 at 5:17 PM, bearophile <bearophileHUGS at lycos.com>wrote:

> Namespace:
>
>  Your gig: https://github.com/D-Programming-Language/dmd/pull/
>> 2952#discussion_r8288045
>>
>
> My enhancement request was for the array[$] syntax. The idea of []s was
> invented by someone else (Timothee Cour?).
>
> I like the practical comments by Hara. If Kenji thinks the []s is not
> useful for efficiency (because the efficiency can be obtained with just
> improvements of the compiler), then the []s syntax becomes less necessary.
>
>
> On the other hand this is an interesting use case that compiler
> improvements alone could not be enough to allow:
>
> void fun(int[3]) {}
> void main() {
>     int[3] x = [1, 2, 3];
>     fun(x); // OK
>     fun([1, 2, 3]); // error
>     fun([1, 2, 3]s); // OK
> }
>

yes, that was the prime motivation for DIP34, being able to pass
un-ambiguously a static array to a function without having to declare an
intermediate variable first.

when fun() has overloads for both static and non-static arrays (or is just
declared as fun(T)(T a) ), the compiler cannot guess whether fun([1,2,3])
asks for static or dynamic array, and probably has to assume dynamic array.
And int[$] would require declaring a variable before passing it, eg:
int[$]x=[1,2,3].

With [1,2,3]s, there is no ambiguity.





>
>
> Are vector ops supported?
>
> int[6] a;
> a = [1,2,3]s[] + [4,5,6]s[];
>
> DIP34 is still a draft, and it shows, some corner cases are missing in
> that document and need to be found, fleshed out and added to the DIP34.
>
> Bye,
> bearophile
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20131211/a8dcaaf4/attachment.html>


More information about the Digitalmars-d-learn mailing list