Skip to content

Commit

Permalink
Preserve single line function arguments (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 committed Jun 14, 2024
1 parent 8bc5120 commit 84af456
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* Use single-line layout for parens around single-line content. [Issue
1120](https://github.com/tweag/ormolu/issues/1120).

* Allow function arguments to be on the same line even if the full type
(with constraints and foralls) are on multiple lines. [PR
1125](https://github.com/tweag/ormolu/pull/1125)

## Ormolu 0.7.6.0

* Fix Haddock comments on infix constructors
Expand Down
4 changes: 1 addition & 3 deletions data/examples/declaration/class/default-signatures-out.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class Bar a where
( Read a,
Semigroup a
) =>
a ->
a ->
a
a -> a -> a
-- Even more pointless comment
bar
a
Expand Down
4 changes: 1 addition & 3 deletions data/examples/declaration/data/gadt/multiline-out.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ data Foo a where
forall a b.
(Show a, Eq b) => -- foo
-- bar
a ->
b ->
Foo 'Int
a -> b -> Foo 'Int
-- | But 'Bar' is also not too bad.
Bar ::
Int -> Maybe Text -> Foo 'Bool
Expand Down
4 changes: 1 addition & 3 deletions data/examples/declaration/rewrite-rule/type-signature-out.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
z
( g ::
forall b.
(a -> b -> b) ->
b ->
b
(a -> b -> b) -> b -> b
).
foldr k z (build g) =
g k z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ wrapError ::
HasCatch innertag inner (t m'),
HasCatch outertag outer m
) =>
(forall m'. (HasCatch innertag inner m') => m' a) ->
m a
(forall m'. (HasCatch innertag inner m') => m' a) -> m a
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ magnify ::
HasReader innertag inner (t m'),
HasReader outertag outer m
) =>
(forall m'. (HasReader innertag inner m') => m' a) ->
m a
(forall m'. (HasReader innertag inner m') => m' a) -> m a
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ sort' ::
a -> a -> Bool,
?foo :: Int
) =>
[a] ->
[a]
[a] -> [a]
sort' = sort
17 changes: 17 additions & 0 deletions data/examples/declaration/value/function/multiline-types-out.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
foo ::
(Monad m, Show a) =>
a ->
m String
bar ::
( Monad m,
Show a
) =>
a -> m String
multiConstraints ::
(Show a) =>
a ->
a ->
a ->
(Eq a) =>
(Num a) =>
a -> a -> ()
15 changes: 15 additions & 0 deletions data/examples/declaration/value/function/multiline-types.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
foo ::
(Monad m, Show a) =>
a ->
m String

bar ::
(Monad m,
Show a) =>
a -> m String

multiConstraints ::
Show a =>
a -> a -> a ->
Eq a => Num a =>
a -> a -> ()
6 changes: 2 additions & 4 deletions data/examples/other/multiline-forall-out.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ data G where
)
(x :: *)
(y :: *).
f x y ->
G
f x y -> G

f ::
forall
Expand All @@ -32,8 +31,7 @@ f ::
)
(x :: *)
(y :: *).
f x y ->
()
f x y -> ()
f = const ()

type family T f x y where
Expand Down
4 changes: 2 additions & 2 deletions src/Ormolu/Printer/Meat/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ p_hsType' multilineArgs = \case
HsForAllInvis _ bndrs -> p_forallBndrs ForAllInvis p_hsTyVarBndr bndrs
HsForAllVis _ bndrs -> p_forallBndrs ForAllVis p_hsTyVarBndr bndrs
interArgBreak
p_hsTypeR (unLoc t)
located t p_hsType
HsQualTy _ qs t -> do
located qs p_hsContext
space
txt "=>"
interArgBreak
case unLoc t of
HsQualTy {} -> p_hsTypeR (unLoc t)
HsFunTy {} -> p_hsTypeR (unLoc t)
HsFunTy {} -> located t p_hsType
_ -> located t p_hsTypeR
HsTyVar _ p n -> do
case p of
Expand Down

0 comments on commit 84af456

Please sign in to comment.