Skip to content

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

Open
@jslambda

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions