smlfmt icon indicating copy to clipboard operation
smlfmt copied to clipboard

Heuristic for placing fun decl body on separate line

Open MatthewFluet opened this issue 1 year ago • 1 comments

The heuristic for determining whether the body of a function declaration is placed on a newline seems rather conservative and can lead to seemingly wasted horizontal space, especially when mixed with val declarations that do not seem to use the same heuristic.

❯ smlfmt -max-width 45 --preview-only z.sml 
---- z.sml ----
infixr 1 $

val f = fn (g, x) => x
val f = fn (g, x) => g x
val f = fn (g, x) => g $ x
val f = fn (g, x) => g $ g x
val f = fn (g, x) => g $ g $ x
val f = fn (g, x) => g $ g $ g x
val f = fn (g, x) => g $ g $ g $ x
val f = fn (g, x) => g $ g $ g $ g x
val f = fn (g, x) => g $ g $ g $ g $ x
val f = fn (g, x) => g $ g $ g $ g $ g x
val f = fn (g, x) => g $ g $ g $ g $ g $ x
val f = fn (g, x) => g $ g $ g $ g $ g $ g x
val f = fn (g, x) =>
  g $ g $ g $ g $ g $ g $ x

fun f (g, x) = x
fun f (g, x) = g x
fun f (g, x) = g $ x
fun f (g, x) = g $ g x
fun f (g, x) = g $ g $ x
fun f (g, x) =
  g $ g $ g x
fun f (g, x) =
  g $ g $ g $ x
fun f (g, x) =
  g $ g $ g $ g x
fun f (g, x) =
  g $ g $ g $ g $ x
fun f (g, x) =
  g $ g $ g $ g $ g x
fun f (g, x) =
  g $ g $ g $ g $ g $ x
fun f (g, x) =
  g $ g $ g $ g $ g $ g x
fun f (g, x) =
  g $ g $ g $ g $ g $ g $ x
--------

MatthewFluet avatar Mar 09 '23 23:03 MatthewFluet

Ah good point -- I hadn't checked if these two heuristics are consistent with each other.

shwestrick avatar Mar 10 '23 15:03 shwestrick