-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
Optionally present fields: is it possible? #113
Comments
I have found a way to make it a bit less noisy. With this expression
I can now write
But is there a way to avoid specifying a type parameter every time so I could just write |
Usually the way I do this is to provide the user with a default record which they can override or extend using let defaults =
{ cpus =
[] : Optional Double
, memoryMb =
[] : Optional Double
, diskMb =
[] : Optional Double
, numPorts =
[] : Optional Integer
}
in defaults ⫽ { cpus = [ 1 ] : Optional Integer } Judging by #114 it looks like that is already your current approach so I'll address how to deal with overriding recursive types separately in that ticket. I need some more time to think about that one. Also, |
I think it would be more convenient to write |
@gromakovsky: I would like to keep it the way it is. The issues with your proposal are that:
|
I feel @AlexeyRaga’s pain. I think having a way to write a A more advanced step, but a huge help, could be a builtin function
evaluates to
|
@geigerzaehler: I agree that there probably should be some language feature that provides type inference in the non-empty case Here's one idea: add language support for |
That would be great! |
Alright, then I'll try to open a proposal this weekend (ETA: Sunday) |
@Gabriel439 I have the feeling there might be some value in having a different syntax for The What I'm trying to say here is that I think it would be beneficial to replace the |
@f-f: We can do this in two steps: first introduce |
Not having weird corner cases like dhall-lang/dhall-haskell#414 is also a nice advantage in my book, so +1 for making a change. |
@quasicomputational: Note that changing the syntax for That said, I'm still liking the idea of changing the syntax for |
@Gabriel439 +1 for doing the transition in two steps and for facilitating the transition with |
@f-f: Mainly separation of concerns. |
Just an update that there is a delay on this while I finish the work on standardizing serialization. Once that is done then I will proceed with standardizing this |
Sorry for the delay on this, but I have time to standardize this now. There are two ideas that I would like to suggest in the meantime while I am implementing and standardizing this. The first suggestion is possibly using The second suggestion is possibly lowercasing them (i.e. |
Another thing to mention: the simplest way to do this is to make The reason why is that it's simple to rewrite This also slightly simplifies migration because any expression in normal form is already migrated (although expressions not in normal form still need to be explicitly migrated via |
... as discussed in #113 (comment) This adds new `Some`/`None` constructors that will (eventually) displace the `List`-like syntax for `Optional` values. This proposes that `Some`/`None` are the new normal forms for optional literals and that the legacy `List`-like syntax β-normalizes to `Some`/`None`. The reason why is that converting in the opposite direction from `Some t` to `[ t ] : Optional T` would require performing type inference during β-normalization (which would complicate β-normalization). In contrast, converting from `[ t ] : Optional T` is straightforward and only requires dropping the type. Eventually the legacy `List`-like syntax will be dropped after a suitably long migration period.
Alright, I have a pull request up based on the We can continue the discussion there |
... as discussed in #113 (comment) This adds new `Some`/`None` constructors that will (eventually) displace the `List`-like syntax for `Optional` values. This proposes that `Some`/`None` are the new normal forms for optional literals and that the legacy `List`-like syntax β-normalizes to `Some`/`None`. The reason why is that converting in the opposite direction from `Some t` to `[ t ] : Optional T` would require performing type inference during β-normalization (which would complicate β-normalization). In contrast, converting from `[ t ] : Optional T` is straightforward and only requires dropping the type. Eventually the legacy `List`-like syntax will be dropped after a suitably long migration period.
Alright, I will go ahead and close this since I think { cpus = None Double
, memoryMb = None Double
, numPorts = None Integer
} ... and you can override it like this: ./defaults ⫽ { cpus = Some 1 } |
I am prototyping something with
Dhall
and it looks very nice except for one part: I cannot figure out the way to express optionally-present fields.For example, an API dictates that the data type should look like:
Most of the time there is no need to configure all of these fields, so I'd like to be able to use this type as:
Unfortunately, it doesn't seem to be possible, and the only way to use this type that I have found would be to write something like:
which is not a great user experience IMO, especially when the configuration is a bit more complicated/nested.
Is there a way to express optional/optionally present fields in
Dhall
somehow different and simpler for users?Another question: I have found that
dhall-json
generates the following JSON from the example above:Is there a way to not render
null
fields at all, or is it left to post-processing?The text was updated successfully, but these errors were encountered: