www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - enhancement type system

reply baleog <maccarka yahoo.com> writes:
Can i dream that someday D would has an enhancement type system? To do
something like this:

type T = { int[2..17] | string("default") }
type U = { T | None };

or it's a totally bad idea?
Jul 31 2008
next sibling parent reply downs <default_357-line yahoo.de> writes:
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; } }
Jul 31 2008
parent downs <default_357-line yahoo.de> writes:
downs wrote:
   T opAssign(T t) {
     if (!t) throw new Exception("Cannot set NonNull to null!");
     obj = t;
Er, of course, return obj = t;
   }
 }
Jul 31 2008
prev sibling next sibling parent bearophile <bearophileHUGS lycos.com> writes:
baleog:
 Can i dream that someday D would has an enhancement type system? To do
something like this:
Are you talking algebraic data types, like ones in Scala/Haskell? (I suggest people around here to take a look at Scala: optional semicolon, actor-based concurrency, algebraic data types, and more 'modern' things). If you are talking about algebraic data types, then this may indeed require a more powerful type system... it's not a small change (the syntactic part of such changes are very little compared to the changes in the type system), I don't know what type system Scala has. Bye, bearophile
Jul 31 2008
prev sibling parent JAnderson <ask me.com> writes:
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") }
 type U = { T | None };
 
 or it's a totally bad idea?
Is this kinda like a union? -Joel
Jul 31 2008