tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
956 stars 83 forks source link

Better multiline standalone deriving #943

Open brandonchinn178 opened 1 year ago

brandonchinn178 commented 1 year ago

Without DerivingStrategies, it's reasonable to think that "deriving instance" together defines a standalone deriving statement, but with DerivingStrategies, it seems more intuitive for deriving + the strategy to be one unit, and instance + types being another. This makes the styling look just like a normal instance block.

Current

newtype Foo = Foo Int

deriving instance
  Show Foo

deriving via
  (Hex Int)
  instance
    Show Foo

deriving newtype instance
  Show Foo

Desired

newtype Foo = Foo Int

deriving 
  instance Show Foo

deriving newtype
  instance Show Foo

deriving via (Hex Int)
  instance Show Foo

-- if the user explicitly puts it on the next line, perhaps even
-- deriving
--   via (Hex Int)
--   instance Show Foo

Environment

Additional context Related: https://github.com/ghc-proposals/ghc-proposals/pull/446

amesgen commented 1 year ago

Sounds neat, being anticipatorily forward-compatible with https://github.com/ghc-proposals/ghc-proposals/pull/446 could be sufficient reason to change formatting here (multi-line deriving clauses are also usually pretty self-contained), such that this will be a fixed point:

deriving newtype
  instance Show Foo
  instance Read Foo

deriving via -- or also change the newline insertion here
  (Hex Int)  -- as suggested in your examples
  instance
    Show Foo
    Read Foo