Type system question
Bill Baxter
wbaxter at gmail.com
Thu Dec 11 18:09:16 PST 2008
On Fri, Dec 12, 2008 at 10:58 AM, Michel Fortin
<michel.fortin at michelf.com> wrote:
> On 2008-12-10 20:17:54 -0500, "Bill Baxter" <wbaxter at gmail.com> said:
>
>> someFunction(x, y) {
>> return x+y;
>> }
>>
>> addone(x) {
>> val result; /*inferred-type result (in proposed language)*/
>> result = someFunction(x,1);
>> return result;
>> }
>
> Isn't the following already working in D2?
> (I don't have a D2 compiler at hand right now to check)
>
> auto someFunction(X, Y)(X x, Y y) {
> return x+y;
> }
>
> auto addone(X)(X x) {
> auto result = someFunction(x, 1);
> return result;
> }
Does it? Didn't know. Won't have much use for D2 till it's got DWT.
> I agree that the syntax can be improved; I already suggested using "auto"
> for argument types to create function templates, which would give:
>
> auto someFunction(auto x, auto y) {
> return x+y;
> }
>
> auto addone(auto x) {
> auto result = someFunction(x, 1);
> return result;
> }
>
That's a nice suggestion. Doesn't cover all cases, but handles simple
templates very nicely.
I guess the problem is it doesn't mix well with the case where you
need to specify some constraints on the types. Like
someFunc(T,K)(T[K] x, K y)
--bb
More information about the Digitalmars-d
mailing list