From b03f989f364c174b65ef34dcf1e3d52e1d3a89d3 Mon Sep 17 00:00:00 2001 From: Vladislav Zavialov Date: Fri, 12 Jul 2019 12:38:42 +0300 Subject: [PATCH] Bang patterns and splices in lambdas --- .../declaration/value/function/lambda-single-line-out.hs | 6 ++++++ .../declaration/value/function/lambda-single-line.hs | 6 ++++++ src/Ormolu/Printer/Meat/Declaration/Value.hs | 9 ++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/data/examples/declaration/value/function/lambda-single-line-out.hs b/data/examples/declaration/value/function/lambda-single-line-out.hs index 7c67204..e60799d 100644 --- a/data/examples/declaration/value/function/lambda-single-line-out.hs +++ b/data/examples/declaration/value/function/lambda-single-line-out.hs @@ -7,3 +7,9 @@ bar x = baz :: a -> a -> a baz = \ ~x ~y -> x + +zag :: a -> a -> a +zag = \ !x !y -> x + +spl :: a -> a +spl = \ $([p|x|]) -> x diff --git a/data/examples/declaration/value/function/lambda-single-line.hs b/data/examples/declaration/value/function/lambda-single-line.hs index 87ffc1f..025d63d 100644 --- a/data/examples/declaration/value/function/lambda-single-line.hs +++ b/data/examples/declaration/value/function/lambda-single-line.hs @@ -7,3 +7,9 @@ bar x = baz :: a -> a -> a baz = \ ~x ~y -> x + +zag :: a -> a -> a +zag = \ !x !y -> x + +spl :: a -> a +spl = \ $([p|x|]) -> x diff --git a/src/Ormolu/Printer/Meat/Declaration/Value.hs b/src/Ormolu/Printer/Meat/Declaration/Value.hs index 67b7b14..c486222 100644 --- a/src/Ormolu/Printer/Meat/Declaration/Value.hs +++ b/src/Ormolu/Printer/Meat/Declaration/Value.hs @@ -135,9 +135,12 @@ p_match' placer pretty style isInfix m_pats m_grhss = do PatternBind -> stdCase Case -> stdCase Lambda -> do - case unLoc (NE.head ne_pats) of - LazyPat _ _ -> txt "\\ " - _ -> txt "\\" + let needsSpace = case unLoc (NE.head ne_pats) of + LazyPat _ _ -> True + BangPat _ _ -> True + SplicePat _ _ -> True + _ -> False + txt (if needsSpace then "\\ " else "\\") stdCase LambdaCase -> stdCase return inci'