Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign up[Question] Configurations with many optional fields #35
Comments
This comment has been minimized.
This comment has been minimized.
|
I think probably the most straightforward solution is to change the record merge operator (i.e. Then you could provide the user with a default record with all optional values set to empty and let them selectively override them. For example, you could do:
... and then build up the final record like this:
... if you wanted to override the How does that sound? |
This comment has been minimized.
This comment has been minimized.
|
That sounds pretty good. In fact the behaviour you are describing is what I expected that the merge operator would do (until I read the docs!) It still means the for each resource I want to create, I need to expose two values: a function to actually create the resource (
It's probably ok, and definitely cleaner than my current haskell EDSL. I guess I pine for python's named function argument passing, ie:
Of course, there's a whole bunch of reasons why I don't want to use python (typing for a start), but I do like the argument passing :-) |
This comment has been minimized.
This comment has been minimized.
|
So I may need to introduce a separate operator for this purpose, mainly due to the fact that the
So if nobody objects what I think I will do instead is introduce a new right-biased non-recursive merge operator for this purpose. I might name the operator |
Gabriel439
added a commit
that referenced
this issue
Apr 13, 2017
This comment has been minimized.
This comment has been minimized.
|
I have a pull request up for the proposed change here: #36 |
This comment has been minimized.
This comment has been minimized.
|
Nice! The change looks great. The example is written with defaults as |
This comment has been minimized.
This comment has been minimized.
|
Yes, this would work with any type, not just |
Gabriel439
closed this
in
ec1bb99
Apr 14, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks! |
This comment has been minimized.
This comment has been minimized.
|
You're welcome! :) |
timbod7 commentedApr 13, 2017
I'm looking at Dhall for the first time, and I like what I see so far.
When building systems the configuration for a component may have a small number of required fields, and a larger number of fields that have sensible defaults, but may be overriden as required. For an example, consider the terraform specfication for an AWS EC2 instance. There are 24 configurable fields, some of which must be provided, the others have useful defaults.
How would this be expressed in dhall? The straighforward translation would seem to to use the Optional builtin, ie:
But the issue with this is that I have to provide all of the optional fields, along with their types, ie:
With many optional values, this is verbose and tedious. It also doesn't allow optional values to be added without updating all of the call sites. Is there a means by which I only have to name the required fields, along with any options that I wish to override?