anoma / juvix

A language for intent-centric and declarative decentralised applications
https://docs.juvix.org
GNU General Public License v3.0
452 stars 52 forks source link

Improve the formatting of multiline list literals #2466

Closed paulcadman closed 12 months ago

paulcadman commented 1 year ago

In this issue contains suggestions on how to improve the formatting of list literals that do not fit on a single line. They follow the ormolu formatting rules that we're familiar with from Haskell.

 Example 1

Unformatted code

l : List Nat := [aFunction someLongLongLongLongLongLongArg; aFunction someLongLongLongLongLongLongArg];

Current formatting

l : List Nat :=
  [aFunction someLongLongLongLongLongLongArg; aFunction
    someLongLongLongLongLongLongArg];

Suggested formatting:

l : List Nat :=
  [ aFunction someLongLongLongLongLongLongArg
  ; aFunction someLongLongLongLongLongLongArg
  ];

Example 2

Unformatted code / Current formatting

The following is a list literal that cannot fit on one line.

l : List Nat :=
  [someLongLongLongLongLongLongArg; someLongLongLongLongLongLongArg; someLongLongLongLongLongLongArg];

Suggested formatting

l : List Nat :=
  [ someLongLongLongLongLongLongArg
  ; someLongLongLongLongLongLongArg;
  ; someLongLongLongLongLongLongArg
  ];

Example 3

Unformatted code / Current formatting

The following is a list literal that fits on one line. We should not change this.

l : List Nat := [1;2;3];

Suggested formatting

l : List Nat := [1; 2; 3];
lukaszcz commented 1 year ago
l : List Nat := [1;2;3];

I would suggest [1; 2; 3], i.e., with spaces. It's similar to putting a space after a comma.

paulcadman commented 1 year ago
l : List Nat := [1;2;3];

I would suggest [1; 2; 3], i.e., with spaces. It's similar to putting a space after a comma.

Thank you - yes this is better.

janmasrovira commented 1 year ago

Have you thought about this format?

l : List Nat :=
  [  someLongLongLongLongLongLongArg
   ; someLongLongLongLongLongLongArg
   ; someLongLongLongLongLongLongArg
  ];

It makes it easier to append elements to the list, which is quite common.