static arrays becoming value types

Leandro Lucarella llucax at gmail.com
Tue Oct 20 17:38:33 PDT 2009


language_fan, el 20 de octubre a las 19:19 me escribiste:
> >> One nasty thing about D's structs is that they don't have structural
> >> equivalence relation unlike tuples. So you need to use the same
> >> container struct type to get the same semantics. To achieve that you
> >> would need some kind of STuple on standard library level or other kinds
> >> of hacks.
> >> 
> >> What I find unfortunate in D is that your abstractions come in two
> >> sizes - either you use the modest tiny construct that does not scale
> >> elegantly or the enormous hammer to crush things down theatretically.
> > 
> > I don't understand very well what are you saying anyways...
> 
> Because of the unnecessary nominal typing in D's tuple emulation, 
> redefinitions of Tuples do not have implicit equivalence relation:
> 
>   struct Tuple(T...) {
>     T t;
>   }
>   struct Tuple2(T...) {
>     T t;
>   }
> 
>   void main() {
>     Tuple!(int,int) a;
>     Tuple!(int,int) b;
>     Tuple2!(int,int) c;
> 
>     assert(a == b); // ok
>     assert(a != c); // Error: incompatible types for ((a) != (b))
>   }
> 
> In some other language:
> 
>   val a = (1,2) : [Int,Int]
>   val b = (1,2) : [Int,Int]
>   val c = (2,3) : [Int,Int]
> 
>   assert(a == b); // ok
>   assert(a != c); // ok
> 
> Did you get it now?

Yes, thanks for the clarification.

> Real tuple types do not have a special type tag which gets injected 
> implicitly with structs. So every time you try to do something 
> lightweight by emulating tuples, you need to refer to the global Tuple 
> type or bang your head to the wall.

Yes, D support for tuples is way far from ideal.

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
If you want to be alone, just be alone
If you want to watch the sea, just watch the sea
But do it now, timing is the answer, do it now
Timing is the answer to success



More information about the Digitalmars-d mailing list