OCamlPro / ocp-indent

Indentation tool for OCaml, to be used from editors like Emacs and Vim.
http://www.typerex.org/ocp-indent.html
Other
200 stars 63 forks source link

Consistent indentation of `fun` after `let` #323

Open Julow opened 1 year ago

Julow commented 1 year ago

Apply the same indentation for:

let f =
  fun x ->
  y

and:

let _ =
  let f =
    fun x ->
    y
  in
  ()

The reason for this change is that a top-level-let can be interpreted as a LetIn, for example:

module M = struct
  let indentation_after_fun =
    fun foo ->
    bar
end

We found this problem while working on OCamlformat for Janestreet. An other solution to this problem would be to correctly interpret the let. What do you think ?

AltGr commented 1 year ago

Thanks! I don't have a strong opinion about the change (although I do like the fact that the whole body doesn't change indentation depending on whether there is a newline before the fun) — but about this part:

The reason for this change is that a top-level-let can be interpreted as a LetIn, for example:

That sounds like a bug that could be fixed, could you have a look at: https://github.com/OCamlPro/ocp-indent/pull/323/files#diff-d2b011b2196f3fb28d20777c036018fd9b3073c4211cfb45440815d778a987bbR942-R947

Thanks!

Julow commented 1 year ago

I fixed the detection of Let in https://github.com/OCamlPro/ocp-indent/pull/324 but I think this PR also make sense as it fixes an inconsistency.

ceastlund commented 1 year ago

We've looked at this change on our code at Jane Street, the ouput looks fine and more consistent than before. I'm in favor of this change.