Type system question

Michel Fortin michel.fortin at michelf.com
Thu Dec 11 17:58:31 PST 2008


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;
	}

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;
	}

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list