Type system question

Michel Fortin michel.fortin at michelf.com
Fri Dec 12 04:25:21 PST 2008


On 2008-12-11 21:09:16 -0500, "Bill Baxter" <wbaxter at gmail.com> said:

> On Fri, Dec 12, 2008 at 10:58 AM, Michel Fortin
> 
>> 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.

In a way, it's bringing D closer to scripting languages. The major 
difference being that any type propagation error in a given code path 
will be caught at compile-time instead of at runtime.


> 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)

Hum, well, we could try this:

	auto someFunc(auto[typeof(y)] x, auto y)
	{ ... }

I'll concede that the current template syntax with parametrized types 
may be better in this case, and that it's absolutely necessary for 
expressing the constrains in this function:

	auto someFunc(T,K)(T[K] x, K[T] y)
 	{ ... }

But anyway, if you prefer to keep things simple, don't specify the constrains.

	auto someFunc(auto x, auto y)
	{ ... }


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




More information about the Digitalmars-d mailing list