Bang patterns and splices in lambdas
commitb03f989f364c174b65ef34dcf1e3d52e1d3a89d3
authorVladislav Zavialov <vlad.z.4096@gmail.com>
dateFri 12 Jul 2019, 12:38 (7 years ago)
parenta7265df
data/examples/declaration/value/function/lambda-single-line-out.hs+6
@@ -7,3 +7,9 @@ bar x =
77
88baz :: a -> a -> a
99baz = \ ~x ~y -> x
10+
11+zag :: a -> a -> a
12+zag = \ !x !y -> x
13+
14+spl :: a -> a
15+spl = \ $([p|x|]) -> x
data/examples/declaration/value/function/lambda-single-line.hs+6
@@ -7,3 +7,9 @@ bar x =
77
88baz :: a -> a -> a
99baz = \ ~x ~y -> x
10+
11+zag :: a -> a -> a
12+zag = \ !x !y -> x
13+
14+spl :: a -> a
15+spl = \ $([p|x|]) -> x
src/Ormolu/Printer/Meat/Declaration/Value.hs+6−3
@@ -135,9 +135,12 @@ p_match' placer pretty style isInfix m_pats m_grhss = do
135135 PatternBind -> stdCase
136136 Case -> stdCase
137137 Lambda -> do
138− case unLoc (NE.head ne_pats) of
139− LazyPat _ _ -> txt "\\ "
140− _ -> txt "\\"
138+ let needsSpace = case unLoc (NE.head ne_pats) of
139+ LazyPat _ _ -> True
140+ BangPat _ _ -> True
141+ SplicePat _ _ -> True
142+ _ -> False
143+ txt (if needsSpace then "\\ " else "\\")
141144 stdCase
142145 LambdaCase -> stdCase
143146 return inci'