Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dangling tuples, lists, arrays and records #661

Open
Niols opened this issue Dec 1, 2023 · 0 comments
Open

Dangling tuples, lists, arrays and records #661

Niols opened this issue Dec 1, 2023 · 0 comments
Labels

Comments

@Niols
Copy link
Member

Niols commented Dec 1, 2023

Is your feature request related to a problem? Please describe.

Topiary's default OCaml formatting is very aerated (especially in multi-line mode), which I enjoy quite a lot. However, sometimes, I find it too aerated and I wished some things stayed on the same line. This is for instance the case with lists, arrays, records, and maybe tuples. I feel we could often opt for a slightly more compact style by making them dangle at the end of the previous line. I think this is also a common OCaml style.

Describe the solution you'd like

Record types are actually already kept dangling by Topiary:

type foo = {
  x : int;
  y : float;
}

but not records are almost never dangling in other situations:

My inputTopiary's output
let foo = {
  x = 2;
  y = 12.;
}
let foo =
  {
    x = 2;
    y = 12.;
  }
let () =
  let foo = {
    x = 2;
    y = 12.;
  }
  in
  something_with_foo
let () =
  let foo =
    {
      x = 2;
      y = 12.;
    }
  in
  something_with_foo
let () =
  my_function {
    x = 2;
    y = 12.;
  }
let () =
  my_function
    {
      x = 2;
      y = 12.;
    }
let () =
  my_function @@ {
    x = 2;
    y = 12.;
  }
let () =
  my_function @@
    {
      x = 2;
      y = 12.;
    }

I don't know about dangling in function applications, because I feel this might only make sense for the last argument of that application. However, I do feel it might make sense in a let or after an operator such as @@.

Lists and arrays would deserve a similar treatment, at least for consistency (and they don't occur in types). And maybe we should also apply the same logic to multi-line tuples, but somehow I'm less certain about this one.

Describe alternatives you've considered

Frankly, the current style is quite good. Maybe we should at least make it more consistent (record types are dangling but nothing else) but apart from that I'm not entirely sure we need those changes. I at least wanted to start a discussion on this.

Additional context

Related to #660 which covers dangling fun . -> and to #657 for the treatment of operators. @aspiwack I imagine you might have an opinion on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant