Dhall leading commas removed by dhall format

dhall format seems to remove the first leading comma in records.

It is a surprise for me to see
{
, key1 = “hello”
, key2 = “world”
}

becoming

{ key1 = “hello”, key2 = “world” }

I might be missing something but this behavior seems both confusing and troublesome (further updates are more difficult to write).

As an addon note, the behavior doesn’t look consistent with how record completions appear here

Yes, this is intentional behavior. Record completions preserve the leading comma if they span more than one line, but normal records do not.

At the time I changed how record completions were formatted I also proposed formatting normal records in the same way, but I received some pushback against that, so I chose to leave things the way they were.

Thanks for the explanation.

This is quite a shame in my situation.

I am using dhall to generate a skeleton of infrastructure rules in an Openshift cluster. Developers would fill in a dhall form and automatically get a project (namespace) with correct defaults for quotas, …

I would like these forms to be as simple as possible as they will be consumed by many developers that know nothing about dhall. So ideally just records.

It would be really convenient to format these inputs automatically with dhall format but I don’t believe user will like to see the current formatting rules applied on these simple records.

How can I possibly justify such arbitrary re-format in this context. For instance the following file:

{
, `limits.cpu` = "2"
, `requests.cpu` = "1"
, `limits.memory`= "2Gi"
}

is now

{ `limits.cpu` = "2", `requests.cpu` = "1", `limits.memory` = "2Gi" }

The user pulls back the file from the SCM later and wants to add a new constraint …

Is there any chance the decision gets revised in the future ?

Anyhow for the time being, I guess the best option is to avoid dhall format on such trivial dhall forms.

In this kind of situation, I wouldn’t bother with dhall format, just type-check whatever the user gives you and import it into the “real” Dhall expression (which you own and do run dhall format on).

I still think there is something I can do here. I might be able to preserve some parts of the original formatting. Specifically, I think I can preserve the leading separator if present and also preserve multiline formatting if present.

1 Like

@PierreR: So it is possible to do, but it’s highly disruptive to the Haskell API, so I may postpone this for now unless there is really strong demand for this. If anybody wants to study what I did so far, I pushed a branch with my in-progress work here:

1 Like