tweag / topiary

https://topiary.tweag.io/
MIT License
575 stars 29 forks source link

Spacing in single-line records #729

Closed Niols closed 2 months ago

Niols commented 2 months ago

As of 1720fa963fdf65e9c767edbe02132ccab4078f5a, Topiary formats:

[a; b; c]
;;
[|a; b; c|]
;;
{a; b; c}
;;
type x = [`Foo | `Bar]
;;
type x = [> `Foo | `Bar]
;;
type x = [< `Foo | `Bar]
;;
type x = {a: int; b: int; c: int}

as

[a; b; c]
;;
[|a; b; c|]
;;
{ a; b; c }
;;
type x = [`Foo | `Bar]
;;
type x = [> `Foo | `Bar]
;;
type x = [< `Foo | `Bar]
;;
type x = { a: int; b: int; c: int }

Note how the record, both value and type, is the only one that gets extra spacing. It would be worth making this consistent. I think we should go for no spaces.

Niols commented 2 months ago

Note that this also happens in patterns:

match foo with
| {bar; baz} -> bar + baz
| Qux {quux} -> quux

gets formatted as

match foo with
| { bar; baz } -> bar + baz
| Qux { quux } -> quux
Niols commented 2 months ago
let foo {bar; baz} (Qux {quux}) =
  bar + baz - quux

->

let foo { bar; baz } (Qux { quux }) =
  bar + baz - quux

(At least, the whole thing is very consistent!