ormolu icon indicating copy to clipboard operation
ormolu copied to clipboard

avoiding recursive `let` bindings

Open sellout opened this issue 5 years ago • 0 comments

Since GHC 8.0, there's no way to prevent let bindings from being recursive. This is a not-uncommon source of bugs. One workaround (for part of the problem) is to chain lets, like

let x = 7 in
let y = x in
let z = y in
  z

With Ormolu, this very quickly results in deep nesting, as each let introduces two levels of indentation.

let x = 7
 in let y = x
     in let z = y
         in z

This is perhaps related to #575, although the underlying justification is different and not all of the approaches there help here.

I actually prefer Ormolu's formatting, and wish GHC would fix this problem internally (like in https://gitlab.haskell.org/ghc/ghc/-/issues/14527). However, until then, it feels like Ormolu is discouraging this workaround.

I'm not sure what a solution looks like. Maybe there's a different approach to avoid the underlying problem that'll work better with Ormolu's current style, or maybe there's a formatting that makes everyone happy XD

sellout avatar Aug 28 '20 17:08 sellout