ocaml / v2.ocaml.org

Implementation of the ocaml.org website.
http://ocaml.org
Other
321 stars 345 forks source link

Formatting guidelines missing example for match #1079

Open ebblake opened 5 years ago

ebblake commented 5 years ago

https://ocaml.org/learn/tutorials/guidelines.html has several recommendations on formatting match patterns, but notably lacks any guidance on the following: when using more than one pattern that both share the same ->, should the second | be indented in relation to the first (to make it obvious that the first lacks ->) or should the | be aligned? Visually, this is the difference between:

List.iter (
  function
  | A -> x
  | B
  | C -> y
  | D -> z
) list

and:

List.iter (
  function
  | A -> x
  | B
    | C -> y
  | D -> z
) list

emacs-tuareg-2.0.10-5.fc29.noarch, as shipped on Fedora, favors indentation of the secondary patterns (the latter style), although that gets in my way when editing a project that favors the style of always aligning the | (the first style). If the style guide were to state a preference for one way or the other, then the tuareg defaults could match that style (whether or not tuareg also adds a user customization to make it easier to change between the two styles).

Chris00 commented 5 years ago

In my opinion, both are fine. Tuareg uses the latter by default because it improves readability by showing the structure. ocamlformat does not and it is OK. You can configure Tuareg to use that style too and even change it per project.