lspitzner / brittany

haskell source code formatter
GNU Affero General Public License v3.0
690 stars 72 forks source link

Inconsistent layout for pattern matching record types vs construction #223

Open mbeidler opened 5 years ago

mbeidler commented 5 years ago

Running brittany on the following program:

data Foo = Foo
  { foo :: Int
  , bar :: String
  , baz :: Bool
  , quux :: Maybe Int
  , a :: Char
  , b :: Bool
  } deriving (Eq, Show)

handleFoo :: Foo -> IO ()
handleFoo foo = case foo of
  Foo { foo = 42
      , bar = "abcdefghijklmnopqrstuvwxyz"
      , baz = True
      , quux = Just 1 } -> putStrLn "bingo!"
  _ -> return ()

buildFoo :: Foo
buildFoo = Foo
  { foo  = 42
  , bar  = "abcdefghijklmnopqrstuvwxyz"
  , baz  = True
  , quux = Just 1
  , a    = 'z'
  , b    = 'b'
  }

produces:

data Foo = Foo
  { foo :: Int
  , bar :: String
  , baz :: Bool
  , quux :: Maybe Int
  , a :: Char
  , b :: Bool
  } deriving (Eq, Show)

handleFoo :: Foo -> IO ()
handleFoo foo = case foo of
  Foo { foo = 42, bar = "abcdefghijklmnopqrstuvwxyz", baz = True, quux = Just 1 }
    -> putStrLn "bingo!"
  _ -> return ()

buildFoo :: Foo
buildFoo = Foo
  { foo  = 42
  , bar  = "abcdefghijklmnopqrstuvwxyz"
  , baz  = True
  , quux = Just 1
  , a    = 'z'
  , b    = 'b'
  }

Notice the inconsistency in layout for pattern match versus record construction. Also, the layout it chose exceeds the maximum characters per line limit.