Proposal to add 'Elements of Programming' Concepts to std.traits

bearophile bearophileHUGS at lycos.com
Sat Jun 16 12:22:23 PDT 2012


Guillaume Chatelet:

> The website is more of a stopgap, the book is way better 
> because it
> shows the paths from concepts to concepts. I should warn the 
> book is not
> easy to read, it's hard and it hurts, but it's good hurt.

I like hard books, if they give something valuable back.


> X10 ( http://x10-lang.org/ ) allows user to add constrains on 
> value domain definition at declaration time. Here are a few
> lines took from the documentation :
>
> * Int{self != 0} is the type of non-zero Ints.
> * Int{self != 0, self != 1} is the type of Ints which are 
> neither zero
> nor one.
> * String{self != null} is the type of non-null strings.
> * Matrix{self.rows == self.cols} is the type of square matrices.

I see. is that semantically different from this (beside being 
shorter)?

struct NoZero {
     int value;
     this(int x) { value = x; }
     alias value this;
     invariant() { assert(value != 0); }
}
void main() {
     auto a = NoZero(5);
     auto b = NoZero(0);
}

Bye,
bearophile


More information about the Digitalmars-d mailing list