-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Go/Ada style subtyping aka C++ "opaque typedef" #13092
Comments
Couldn't find anything very related except for this:
|
So, such types would not really exist the IL level? They would be enforced only at the language level? Also, I think a trivial |
It would be nice to emit some sort of metadata to preserve this information when consuming compiled libraries. Otherwise it will be like F# units of measure but applicable to any types (not just numbers).
Sounds hypothetical. |
@dsaf Thank you for posting this. First use case I can think of is when you pass around the key of entities, so instead of
Ideally I would like to set a sort of global alias somewhere to allow me to write
so that calling There are of course a lot of open points
Just to name a few, but I like to see this discussion started |
Open to ideas. Historically existing keywords tend to be re-used, but I am afraid that
These are types not aliases. So same as other types.
Either preserve as metadata or erase during compilation.
|
Dup of #58 |
It would be great if there was an overhead-free quick way of adding more compile-time verification when using "primitive" types.
For example:
Semantically
name
andaddress
are different, yet they can (mistakenly) be used interchangeably without any compiler warnings or errors. Today the only option to work around this would be introducing two new types, which means runtime overhead having to deal with equality overloads etc.Go and Ada have a way of dealing with this, which looks like type aliases but in addition gives a level of type checking:
https://golang.org/ref/spec#Type_identity
https://en.wikibooks.org/wiki/Ada_Programming/Type_System#Defining_new_types_and_subtypes
Similar feature "opaque typedef" is overdue in C++ as well apparently:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3515.pdf
Relevant SO answers:
http://stackoverflow.com/questions/17538955/overhead-of-type-alias-in-go
http://stackoverflow.com/questions/19334542/why-can-i-type-alias-functions-and-use-them-without-casting
http://programmers.stackexchange.com/questions/328055/why-do-mainstream-strong-static-oop-languages-prevent-inheriting-primitives
Some theory:
http://cstheory.stackexchange.com/questions/10620/how-does-inheritance-differ-from-subtyping
http://cstheory.stackexchange.com/questions/3991/implicit-vs-explicit-subtyping
The text was updated successfully, but these errors were encountered: