on master help sign in
Do not lump together forall and constructors when deciding on layout
commitd96f7e3e00c03f0021a1e302c3e0a50f12813f14 authorMark Karpov <markkarpov92@gmail.com> dateFri 10 Apr 2020, 14:29 (7 years ago) parent9b34248
5 files changed+30−10
CHANGELOG.md+3−2 data/examples/declaration/data/existential-multiline-out.hs+12 data/examples/declaration/data/existential-multiline.hs+7 data/examples/other/multiline-forall-out.hs+1−2 src/Ormolu/Printer/Meat/Declaration/Data.hs+7−6
CHANGELOG.md+3−2
@@ -20,8 +20,9 @@
2020 expressions. [Issue 513](https://github.com/tweag/ormolu/issues/513).
2121
2222* Made rendering of data type definitions, value-level applications, and
23− application of types use the same style. [Issue
24− 427](https://github.com/tweag/ormolu/issues/427).
23+ application of types use the same style. Moreover, existential now doesn't
24+ cause the data constructor be unconditionally rendered in multiline layout
25+ [Issue 427](https://github.com/tweag/ormolu/issues/427).
2526
2627* Implemented support for the new language extension `ImportQualifiedPost`.
2728
data/examples/declaration/data/existential-multiline-out.hs+12
@@ -3,3 +3,15 @@
33data Foo
44 = forall a. MkFoo a (a -> Bool)
55 | forall a. Eq a => MkBar a
6+
7+data Bar
8+ = forall x y.
9+ Bar x y x y
10+
11+data Baz
12+ = forall x y.
13+ Baz
14+ x
15+ y
16+ x
17+ y
data/examples/declaration/data/existential-multiline.hs+7
@@ -3,3 +3,10 @@
33data Foo
44 = forall a. MkFoo a (a -> Bool)
55 | forall a. Eq a => MkBar a
6+
7+data Bar = forall x y.
8+ Bar x y x y
9+
10+data Baz = forall x y.
11+ Baz x y x
12+ y
data/examples/other/multiline-forall-out.hs+1−2
@@ -12,8 +12,7 @@ data D
1212 )
1313 (x :: *)
1414 (y :: *).
15− D
16− (f x y)
15+ D (f x y)
1716
1817data G where
1918 G ::
src/Ormolu/Printer/Meat/Declaration/Data.hs+7−6
@@ -124,18 +124,19 @@ p_conDecl = \case
124124 p_hsType (unLoc con_res_ty)
125125 ConDeclH98 {..} -> do
126126 mapM_ (p_hsDocString Pipe True) con_doc
127− let conDeclSpn =
128− [getLoc con_name]
129− <> [getLoc con_forall]
127+ let conDeclWithContextSpn =
128+ [getLoc con_forall]
130129 <> fmap getLoc con_ex_tvs
131130 <> maybeToList (fmap getLoc con_mb_cxt)
132− <> conArgsSpans con_args
133− switchLayout conDeclSpn $ do
131+ <> conDeclSpn
132+ conDeclSpn =
133+ getLoc con_name : conArgsSpans con_args
134+ switchLayout conDeclWithContextSpn $ do
134135 when (unLoc con_forall) $ do
135136 p_forallBndrs ForallInvis p_hsTyVarBndr con_ex_tvs
136137 breakpoint
137138 forM_ con_mb_cxt p_lhsContext
138− case con_args of
139+ switchLayout conDeclSpn $ case con_args of
139140 PrefixCon xs -> do
140141 p_rdrName con_name
141142 unless (null xs) breakpoint