Skip to content
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

Suggesting a new construct for dealing with optional fields in Dhall defaults #2577

Open
jslambda opened this issue Apr 2, 2024 · 0 comments

Comments

@jslambda
Copy link

jslambda commented Apr 2, 2024

I am working on writing some Elasticsearch queries in Dhall, and defining a value with a lot of parameters can become cumbersome (See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#match-field-params as an example)

Dhall defaults described in https://hackage.haskell.org/package/dhall-1.41.2/docs/Dhall-Tutorial.html#g:12 is a great help, however it requires adding a lot of optional fields in my use-case, which in my opinion, adds noise.
I can see that this problem has been discussed already in #2434 , and I'd like to follow up with some suggestion for adding a new construct/function to Dhall. I'd like to achieve the benefits of Dhall defaults without having to specify optional fields.

Is it a good idea to add a new construct which desugars into Dhall defaults with optional fields? Let's call the new construct OptValueWithDefault

let ThatValue = OptValueWithDefault({
    Type={age: Natural, name:Text, height:Double}, 
    default={age=25}
})

desugars into

let ThatValue = {
    Type={age : Optional Natural, name : Optional Text, height : Optional Double}, 
    default={age=Some 25, name=None Text, height=None Double}
}

and

ThatValue::{ name = "Jerry" }

will desugar into

ThatValue::{ name = Some "Jerry" }

Is this an acceptable addition to Dhall?

Best regards,
Hamid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant