Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have a system set up in C++ to make it trivial to add new unique kinds of IDs (wrappers around ints) as well as vectors that can be indexed only with that kind of ID. So you can have a ShoeVec containing Shoes that is indexable only by ShoeIDs and a ShirtVec containing Shirts that is indexable only by ShirtIDs. It's zero-overhead in optimized builds, of course. You'd be surprised how rarely you have to convert to or from the underlying type.


Fwiw the Haxe language calls this an "abstract type", and they're very useful.

https://haxe.org/manual/types-abstract.html


Generic types are useful, but still should be called as such, or for the new fad: dependent types. Abstract types would not allow instantiation.


Haxe abstract types are distinct from abstract classes, but I need to learn more about dependent types.


Congrats, you almost have Pascal there.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: