How to create distinct types from a single source type? #7753
Unanswered
Dimension4
asked this question in
Q&A
Replies: 1 comment
-
This is a design goal of explicit extension. See #5497 #7094 (comment) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there,
as far as I know, C# doesn't allow you to create distinct types (see Nim, for example). Other than keeping multiple identical implementations with different class / struct names, what options do I have? Does anybody know about an existing source generator that does something in that direction?
Assume I have a
Vector3
type. I usually work in two different coordinate systems. Now using the same type for all liner algebra can be a bit tricky since I always have to make sure that all terms in an equation are operating in the same coordinate system (unless I want to convert between the two). It would be nice to have two distinct types that only convert explicitly to each other. Say I have the following function that correlates two vectors in my two coordinate systems:In this case, the compiler can't help me if I mix up the argument order or pass in two vectors from the same coordinate system. With distinct types, I could do the following:
Beta Was this translation helpful? Give feedback.
All reactions