digitalmars.D.learn - enhancement type system
- baleog (4/4) Jul 31 2008 Can i dream that someday D would has an enhancement type system? To do s...
- downs (16/22) Jul 31 2008 Yay Haskell!
- downs (2/7) Jul 31 2008
- bearophile (6/7) Jul 31 2008 Are you talking algebraic data types, like ones in Scala/Haskell?
- JAnderson (3/9) Jul 31 2008 Is this kinda like a union?
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
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
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
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
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