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
Enhancements to one-of construct #747
Comments
Related CDM initiative: finos/common-domain-model#2805 |
Here is a comparison of three different solutions. I evaluate each of them based on the following five questions.
All comparisons are based on a toy version of the Enhance the current solution (
|
Based on this analysis, I would propose the following.
|
Just a clarification on the model, as we are currently writing it, will look like this with the common elements in AssetBase:
Does this change your analysis at all? In fact, we have also made this slightly worse, as follows
Which means, as it currently stands, when we need to reference an identifier, we need to do this:
So there is an even stronger case for
|
On the proposed migration strategy, can we leverage Minesh’s “pre-processing” concept to implement union on the front end that is actually implemented as one-of in the DSL? That is: View in Rosetta:
Implementation
|
This should work fine!
Hm, the current proposal adds
Currently investigating this. I took a quick look together with Minesh, and we came to the conclusion that it's easier said than done. There is a path I haven't explored yet - more to follow. |
Proposal looks good. A few comments and questions:
|
@Oblongs With regards to your point about:
I don't think the proposal would allow simply to shorten as:
Instead, the approach we discussed to eliminate the extra level on this one is to define:
But it's separate from the issue being discussed here. |
@SimonCockx There is another requirement that we'd like you to consider. Although it's another "killer-feature", it's independent from the above and not on the critical path of migration. When defining a
And then it would be possible to use
Also how would that work in the "nested" |
@lolabeis Great points, some of which I have been consciously "forgetting", given they were not listed as requirements yet.
I see two options here. Just to recapitulate, the question is: how do I access
Either:
Currently I'm leaning towards the first option.
Yes, each of the union cases can be of any type, including data types, enumerations, basic types and other union types. In the long term I see additional benefits such as being able to conform to regulations that require us to either output a number or a string, e.g.,
which can then be serialised into
or
This is something which currently is impossible to model with Rune, and for which clients have asked support for in the past.
Great question! I think supporting a "flat" switch, even for nested unions, will be the most easy to read and write, so you would be able to do something like
Potentially, they could also be "mixed" to provide default cases for nested unions. Suppose that
Note that the order of cases then starts to matter. Writing
This would be part of the migration strategy, but in the end I would disallow this kind of direct access of attributes that are not common, unless a compelling use case arises.
To give it a try, I will use |
Update on this one: this is starting to look promising. We will probably follow this strategy as a quick win, and then incrementally start improving it. |
Interesting. I think this wouldn't be too hard to add. Like you mention, the trickiness lies in how to handle nested choice types. To take your example from before:
I think the most useful interpretation is to flatten again. I assume the use case of representing a choice type as an enum is to indicate the actual type of an instance. Since an actual
It depends on the use case of course. My interpretation could be wrong. But perhaps it's best to continue this discussion in a separate issue. |
I would like to add an alternative
This would be better aligned with other operators such as |
One "use case" I didn't add to the comparison, but which would have been useful, is how to go from a specific type to a choice type, e.g., given a function that accepts an Current solution (
|
Summary of the implementation planBelow are four steps to get us from the current state to full support for choice types. 1. Choice types are supported as syntactic sugar of
|
Fully support this, and I was about to suggest it 😄. I think this would also allow you to do nested
|
Agree with this. With regards to the issue of redefining |
Also with the Direct attribute access (in line with simpler
Using default
Using named item:
|
Agree, let's start a separate issue. |
So you could pass a variable of type |
With the way you redefined the Your flat switch suggestion works and is quite concise, but at the expense of introducing an ordering concern, as you point out. It involves a little magic, whereas the explicit |
Your implementation plan looks sensible. There is potentially a step 5, where we may be able to get rid of the |
The inverse scenario to defining a We already have this enum (simplified):
It might be interesting to be able to say
Of course, it would be possible to refactor |
Thanks for all of the feedback. Since there is a consensus for the initial plan (steps 1 and 2 of #747 (comment)), I will start development for those. Once we get to a stage were we can start the rest of the proposal, we can summarise and continue these threads in a separate issue. |
Background
Rationale
Requirements
asset -> identifier
Summary Deck
The attachment documents these requirements.
RUNE DSL Enhancement for One Of.pptx
The text was updated successfully, but these errors were encountered: