More D newb questions.

Me Here p9e883002 at sneakemail.com
Thu May 8 13:41:53 PDT 2008


BCS wrote:

> Reply to Me,
> 
> > BCS wrote:
> > 
> > > Reply to Me,
> > > 
> > > > 3. Can type systems handle the 'natural' extension of
> >>>T[] ~ T[] -> T[];
> >>>T[] ~ T   -> T[];
> >>>T   ~ T[] -> T[];
> >>>T   ~ T   -> T[];
> > > > Closed. (Yes).
> > > > 4. Can D's type system handle this - Open.
> > > > 
> > > I think that one is closed: yes it can, but as you point out, it
> > > wont. Because it causes inconstancies.
> > > 
> > Surely, if it causes inconsistancies, the D's type system isn't
> > handling it?
> > 
> 
> The inconsistency would be from the users perspective and comes from code
> like this:
> 
> T[] Foo(T) (T a, T b) {return a ~ b; }
> 
> This would work if and only if T is not an array type.
> Foo!(char)('c','b'); //works
> Foo!(char[])("c","b"); // fails
> 
> The compiler is constant in how it does things but does not constantly
> produce what you would expect.

That depends upon the order (precedence) the transformation rules are applied. 
With the ordering shown above, your second example matched the first rule
shown,
and so is processed before it ever gets to the T ~ T -> T[]. 

The first example fails to match on the first three rules and is processed
according to the 4th
and the result is consistant results.

b.
-- 




More information about the Digitalmars-d mailing list