tweag/ormolu

Sort constraint tuples

michaelpj opened this issue · 2 comments

I raised this issue on fourmolu since I expected it wouldn't be something that ormolu wants to do, as it's probably too opinionated, but I thought I should raise it here to just check. Repeating the text here for simplicity.


I think I would like the option to have constraint tuples sorted. The issue is that in code which has a lot of constraints, you often have similar or identical constraint tuples that look quite different due to irrelevant differences in the order. If they were sorted it would make it easier to see the similarities or differences.

To put it another way, at the moment I have to manually make an arbitrary decision about where to add a constraint into a constraint tuple. In such a situation where it is arbitrary I think it's arguable that the formatter should decide, like for imports.

e.g. (before)

doAtThing ::
  (IOE :> es, Concurrent :> es, SomethingElse :> es, EvenMore :> es, ThatsRightMore :> es, IsThisTooMuch :> es) =>
  Args ->
  Eff es ()

vs (after)

doAtThing ::
  (Concurrent :> es, EvenMore :> es, IsThisTooMuch :> es, IOE :> es, SomethingElse :> es, ThatsRightMore :> es) =>
  Args ->
  Eff es ()

Note that even if you used this option you could still group sets of constraints together if you want to by using multiple =>s.

If we did this I'd want it to apply everywhere we have constraint tuples.

Thanks, I definitely also wanted certain things to automatically be sorted in the past. Related tickets are #968 and #996.

Okay. It sounds like there isn't an easy answer to "what to do about comments", which I think makes this a good candidate for inclusion in fourmolu where it can be opt-in.