fourmolu icon indicating copy to clipboard operation
fourmolu copied to clipboard

Support -- | with leading function arrows

Open roelvandijk opened this issue 2 years ago • 3 comments

Describe the option you'd like to add haddock-style-parts

Option that controls the formatting of haddock comments attached to parts of a declaration. This is currently controlled by the function-arrows option. I would like to format haddock comments attached to parts of a declaration differently from function-arrows.

Values: null, leading, trailing

The null setting would keep the current behavior.

Show a code example exemplifying the different option settings

Example with function-arrows: leading and haddock-style-parts: trailing:

foo 
  -- | An integer
  :: Int 
  -- | A character
  -> Char 
  -- | The result
  -> Bool

Example with function-arrows: trailing and haddock-style-parts: leading:

foo ::
  Int ->
  -- ^ An integer
  Char ->
  -- ^ A character
  Bool
  -- ^ The result

Partly inspired by this comment: https://github.com/fourmolu/fourmolu/issues/266#issuecomment-1766608579

roelvandijk avatar Oct 19 '23 11:10 roelvandijk

I reallise this option should probably also account for the haddock-style when documenting record fields. In that case haddock-style-parts should have the exact same meaning as for parts of a type declaration. When set to null fourmolu should revert back to the default behaviour based on comma-style.

roelvandijk avatar Oct 19 '23 11:10 roelvandijk

I don't think your proposed function syntax will work. If you run haddock on that code, does it generate the correct docs?

brandonchinn178 avatar Oct 19 '23 14:10 brandonchinn178

Never mind, apparently GHC 9.0 supports this.

I'm in favor of adding a haddock-placement option that defaults to leading when function-arrows is trailing and vice-versa!

brandonchinn178 avatar Jun 02 '24 02:06 brandonchinn178