ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Fix misaligned higher-order functor parameters

Open gpetiot opened this issue 4 years ago • 3 comments

I made some experiments to fix #1678, so far the diff on the conventional profile looks good. cc @CraigFe since you opened the issue.

The idea is to not put the beginning of the functor on the same line as the module opening if the functor signature is going to be complex, I find it easier to read. Thoughts?

The example of #1678 looks like this:

module F1            
    (G : functor (_ : T) -> T) (A : sig
      val x : int
    end) =
struct end

module F2
    (G : functor (_ : T) ->
           T_________________________________________________________________________
    )
    (A : sig
      val x : int
    end) =
struct end

module F3
    (G : functor
           (_ : T____________________________________________)
           (_ : T____________________________________________)
           ->
           T)
    (A : sig
      val x : int
    end) =
struct end

gpetiot avatar Aug 06 '21 14:08 gpetiot

I agree that it would be more readable to be less eager about putting the beginning of complex functors on the same line. But I think that it would still be better to put sig at the end of the preceding line rather than on its own line and increasing the indentation of the whole signature body. The sig token itself does not add any readability.

jberdine avatar Aug 06 '21 14:08 jberdine

But I think that it would still be better to put sig at the end of the preceding line rather than on its own line and increasing the indentation of the whole signature body.

It's fixed, I've also added more tests, and updated the diff at the beginning of the issue. I think it would be nice to have this merged for 0.20.0.

gpetiot avatar Oct 29 '21 08:10 gpetiot

@CraigFe does that fix every case you encountered?

gpetiot avatar Nov 08 '21 12:11 gpetiot