Purpose of comments and the standard

I recently saw a tweet about JSON comments.

The tl;dr is that comments were used as a kind of out of band communication to give directives to software that consume JSON and thus were removed.

What is the current status in Dhall? Comments are removed in the normalized form but are comments available to the implementations for implementing custom extensions? Or is this behavior explicitly forbidden?

I had a look at the Semantics document but I couldn’t find anything comment related, should we explicitly state that they must not have any effect on the expression processing?

@zarel: From the standard’s point of view comments are treated as whitespace:

… and are also not preserved in the binary encoding (which is essentially what we use as the standard “syntax tree” whenever there are any ambiguities):

… so from the standard’s point of view comments are indeed semantically invisible.

However, the Haskell implementation is slowly adding support for preserving comments, although that’s mainly for preserving comments for dhall format.

We don’t ban the use of comments like JSON does, but we also don’t recommend using them for out-of-band directives.

1 Like

If you actually have a use case for out-of-band directives, we should discuss that and add them as a proper pragma syntax of some kind.