ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Feature request: Support `--type-decl=sparse` for small types

Open enaudon opened this issue 4 years ago • 3 comments

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

Currently, single-field records and single-case variants are squeezed onto one line, whenever possible.

type t = Foo of int

type t = {foo : int}

I've tried controling this with the --type-decl option, but it appears that OCamlFormat ignores this option for types like these.

Describe the solution you'd like

It would be great if it were possible to format these types across multiple lines, and with a leading | for variants.

type t =
  | Foo of int

type t = {
  foo : int
}

This is a bit more verbose, yes, but it is also a bit more readable, IMHO. Either making these types obey the --type-decl option, or providing a separate option both seem like they would be reasonable approaches here.

enaudon avatar Mar 04 '20 15:03 enaudon

What about

type t = { foo : int }

i.e. surround with spaces?

ksromanov avatar Mar 04 '20 15:03 ksromanov

Sorry for the late answer. I agree on the idea, so far this behavior (type-decl=sparse) is only enforced for the janestreet profile, if that's okay for you @ceastlund that's a change we can integrate to the profile.

That could also improve the readability for type-decl=compact (if that is only applied for variants and records that does not go too far against the compact spirit of the option). Thoughts @jberdine (for ocamlformat profile) and @samoht (for the default profile) ?

gpetiot avatar Nov 04 '21 15:11 gpetiot

I'm not fond of this for the default profille.

samoht avatar Nov 04 '21 16:11 samoht