ADT formatting: why no leading pipe support?

Why doesn’t PureScript support the format like OCaml and others where you can have a leading | pipe?

data Foo =
  | Bar Int
  | Baz Int

instead of the current

data Foo
  = Bar Int
  | Baz Int

The biggest advantage is the consistent left-hand column as well as the ability to easily insert a new first item. Some may say it also adds consistency with all of the other keywords like type … = and newtype … =, both of which prefer to a newline after the = with current formatting tooling.

7 Likes

+1 for this. It would solve my biggest gripe with moving from purty to purs-tidy, which is the inconsistency with where the = is placed in ADT definitions vs. other type definitions like type and newtype, as mentioned above.

1 Like

Related: trailing commas in record and array literals and binders.

But why not fully generalize? There’s no reason we couldn’t support leading and trailing delimiters in both of these contexts and more: import groups, row types, case x, y, z of ... heads, functional dependencies! No ambiguities are introduced by allowing any of this, and I have the parser patch to prove it.

Some people just want to watch the world burn, specifically from the final, inevitable clash between the acolytes of

import Foo.Bar
  (
  , alpha
  , bravo
  )

and the devotees of

import Foo.Bar (
  alpha,
  bravo,
)

(Am I joking? Is this a good idea? I’m not even sure myself.)

5 Likes

Please do it! it is so annoying when you have to comment out a field of a record or element of an array and then have to reformat everything because trailing/leading commas are not allowed. typescript has it, scala has it, and I wish Purescript also had this

1 Like

Huge +1 to this and also to potentially generalizing it for leading commas. It personally took me a bit to get to this style of formatting in OCaml although it’s functionally (and aesthetically) nicer than the leading = sign.

3 Likes

I’ve shared my maximalist parser patch here: https://github.com/purescript/purescript/pull/4345

Still not entirely sure it’s the best thing to do but I wrote it so I figured I might as well share it.

6 Likes