ennocramer / floskell

Floskell is a flexible Haskell source code pretty printer.
BSD 3-Clause "New" or "Revised" License
178 stars 22 forks source link

More liberal way of aligning matches #83

Open alexgerdes opened 2 months ago

alexgerdes commented 2 months ago

The current implementation is quite restrictive in aligning matches. For example, if one function binding has a where-clause, aligning is abandoned. The same goes for if a function binding has a guarded right hand side. This commit allows for a more liberal way of aligning matches; something that I find myself doing all the time.

Consider the following snippet:

fun [] = 0
fun [_] = n
 where
  n = 1
f un (x : y : z : zs)
  | x > n = 2
  | otherwise = 3
 where
  n = 42

It will get formated as follows:

fun []        = 0
fun [_]       = n
 where
  n = 1
fun (x : y : z : zs)
  | x > n     = 2
  | otherwise = 3
 where
  n = 42

This way of aligning is nicely controlled by the limits, e.g., setting the limit to 6 will not align the equal signs in this particular example.