dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
912 stars 213 forks source link

associative lists need some love #2432

Closed geniusisme closed 1 year ago

geniusisme commented 2 years ago

This is probaly a mix between core dhall and dhall-to-yaml

Consider the following:

〉'toMap { one = 1, two = 2}' | dhall-to-yaml
one: 1
two: 2

Good so far. Now let's try this:

〉'toMap { 1 = one, 2 = two}' | dhall-to-yaml

Error: Invalid input

(input):1:9:
  |
1 | toMap { 1 = one, 2 = two}
  |         ^
unexpected '1'
expecting ',', =, any label, keyword, whitespace, or }

But why? Let's dig deeper:

〉'[ { mapKey = 1, mapValue = "one"} ]' | dhall-to-yaml
- mapKey: 1
  mapValue: one

Not the result we were looking for. Maybe this?

〉'[ { mapKey = "1", mapValue = "one"} ]' | dhall-to-yaml
'1': one

Ok, we made this work. But still, this is not ideal. Preferably, there is a way to getting just 1: one. Also, it would be nice to work with Natrurals in the dhall code. And, of course, having toMap to be more generic would be nice, too.

TristanCacqueray commented 2 years ago

Not sure if that helps, but you can also use backtick with this syntax:

{ `1` = "one" }

dhall-to-yaml produces:

'1': one
mmhat commented 1 year ago

Closing this one since an solution to the problem has been provided. Please reopen if the answer is unsatisfying.