ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Style suggestion: punning syntax for label arguments with casting coercion

Open mbarbin opened this issue 11 months ago • 4 comments

This is a style suggestion to support the label punning when the labeled argument is casted with the :> syntax.

Current formatting Please copy-paste your code and the formatting that is currently applied to it.

let f ~x = x
let coerce_punning x = f ~(x : int)
let cast_coerce_punning x = f ~x:(x :> int)

The coerce_punning works already. The request is about the second item.

Describe the formatting you'd like A clear and concise description of what you want to happen.

let cast_coerce_punning x = f ~(x :> int)

Additional context

This is quite minor. This is motivated for more consistency. I don't know off-hand from which ocaml-version this punning syntax was supported. Thank you!

mbarbin avatar Jan 30 '25 10:01 mbarbin

This seems to work with the to-be-released version. Do you confirm ?

Julow avatar Oct 23 '25 15:10 Julow

I can't get it to work no. I tried the rev 5efba0c5db78fa00e11924829ae4ad38ad555176 and tried different combinations of:

ocaml-version = {5.4, 5.3}
profile = {janestreet, conventional}

Is there a particular setting to enable?

I'm looking at a function argument that looks like this:

 ~path:(path :> Fpath.t) 

If I modify it to:

 ~(path :> Fpath.t) 

ocamlformat re-add the original form, without the punning.

mbarbin avatar Oct 23 '25 16:10 mbarbin

You are right! Changing ocaml-version doesn't make the new formatting stick. OCamlformat is not aware of this new syntax yet

Julow avatar Oct 27 '25 11:10 Julow

Would you like to implement this new formatting ? I think this could be done by modifying fmt_label_arg at https://github.com/ocaml-ppx/ocamlformat/blob/main/lib/Fmt_ast.ml#L1717 We don't have a central place that defines the versions the various syntaxes were added in, but this could be added too.

Julow avatar Oct 27 '25 11:10 Julow