enhancement type system
downs
default_357-line at yahoo.de
Thu Jul 31 14:30:41 PDT 2008
baleog wrote:
> Can i dream that someday D would has an enhancement type system? To do something like this:
>
> type T = { int[2..17] | string("default") }
Yay Haskell!
Seriously, the closest AFAIK is 2.0's opDot plus implicit cast .. you could create a type that enforces being between 2 and 17 for as long as possible (as far as type deduction will let it), then falls back to int when an int is needed.
> type U = { T | None };
>
> or it's a totally bad idea?
2.0's opDot goes towards this direction.
If I understand it correctly, it will let us code like this:
struct NonNull(T) {
T obj;
T opDot() {
debug if (!obj) throw new Exception("Object has somehow become null!");
return obj;
}
T opAssign(T t) {
if (!t) throw new Exception("Cannot set NonNull to null!");
obj = t;
}
}
More information about the Digitalmars-d-learn
mailing list