Skip to content

Commit e463dc6

Browse files
isovectorjneira
andauthored
Wingman: Use infix notation for operator applications (#1675)
* Use infix notation for operator applications * Update tests * Add test suggest by Ailrun * Use isSymOcc Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>
1 parent 7db9a1b commit e463dc6

17 files changed

+38
-14
lines changed

plugins/hls-tactics-plugin/src/Wingman/CodeGen.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import GHC.SourceGen.Binds
2626
import GHC.SourceGen.Expr
2727
import GHC.SourceGen.Overloaded
2828
import GHC.SourceGen.Pat
29+
import GhcPlugins (isSymOcc)
2930
import PatSyn
3031
import Type hiding (Var)
3132
import Wingman.CodeGen.Utils
@@ -203,3 +204,12 @@ buildDataCon should_blacklist jdg dc tyapps = do
203204
& #syn_trace %~ rose (show dc) . pure
204205
& #syn_val %~ mkCon dc tyapps
205206

207+
208+
------------------------------------------------------------------------------
209+
-- | Make a function application, correctly handling the infix case.
210+
mkApply :: OccName -> [HsExpr GhcPs] -> LHsExpr GhcPs
211+
mkApply occ (lhs : rhs : more)
212+
| isSymOcc occ
213+
= noLoc $ foldl' (@@) (op lhs (coerceName occ) rhs) more
214+
mkApply occ args = noLoc $ foldl' (@@) (var' occ) args
215+

plugins/hls-tactics-plugin/src/Wingman/Tactics.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import DataCon
2222
import Development.IDE.GHC.Compat
2323
import GHC.Exts
2424
import GHC.SourceGen.Expr
25-
import GHC.SourceGen.Overloaded
2625
import Name (occNameString, occName)
2726
import Refinery.Tactic
2827
import Refinery.Tactic.Internal
@@ -204,7 +203,7 @@ apply hi = requireConcreteHole $ tracing ("apply' " <> show (hi_name hi)) $ do
204203
pure $
205204
ext
206205
& #syn_used_vals %~ S.insert func
207-
& #syn_val %~ noLoc . foldl' (@@) (var' func) . fmap unLoc
206+
& #syn_val %~ mkApply func . fmap unLoc
208207

209208

210209
------------------------------------------------------------------------------

plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ spec = do
5050
autoTest 2 16 "AutoEmptyString.hs"
5151
autoTest 7 35 "AutoPatSynUse.hs"
5252
autoTest 2 28 "AutoZip.hs"
53+
autoTest 2 17 "AutoInfixApply.hs"
54+
autoTest 2 19 "AutoInfixApplyMany.hs"
55+
autoTest 2 25 "AutoInfixInfix.hs"
5356

5457
failing "flaky in CI" $
5558
autoTest 2 11 "GoldenApplicativeThen.hs"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test :: (a -> b -> c) -> a -> (a -> b) -> c
2+
test (/:) a f = _
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test :: (a -> b -> c) -> a -> (a -> b) -> c
2+
test (/:) a f = a /: f a
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test :: (a -> b -> x -> c) -> a -> (a -> b) -> x -> c
2+
test (/:) a f x = _
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test :: (a -> b -> x -> c) -> a -> (a -> b) -> x -> c
2+
test (/:) a f x = (a /: f a) x
3+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test :: (a -> b -> c) -> (c -> d -> e) -> a -> (a -> b) -> d -> e
2+
test (/:) (-->) a f x = _
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test :: (a -> b -> c) -> (c -> d -> e) -> a -> (a -> b) -> d -> e
2+
test (/:) (-->) a f x = (a /: f a) --> x
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
fJoin :: (Monad m, Monad f) => f (m (m a)) -> f (m a)
2-
fJoin = fmap (\ mma -> (>>=) mma id)
2+
fJoin = fmap (\ mma -> mma >>= id)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{-# LANGUAGE ScopedTypeVariables #-}
22

33
fJoin :: forall f m a. (Monad m, Monad f) => f (m (m a)) -> f (m a)
4-
fJoin = let f = ( (\ mma -> (>>=) mma id) :: m (m a) -> m a) in fmap f
4+
fJoin = let f = ( (\ mma -> mma >>= id) :: m (m a) -> m a) in fmap f

plugins/hls-tactics-plugin/test/golden/KnownBigSemigroup.hs.expected

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,5 @@ data Big a = Big [Bool] (Sum Int) String (Endo a) Any
55
instance Semigroup (Big a) where
66
(<>) (Big l_b7 si8 l_c9 ea10 a11) (Big l_b si l_c ea a)
77
= Big
8-
((<>) l_b7 l_b)
9-
((<>) si8 si)
10-
((<>) l_c9 l_c)
11-
((<>) ea10 ea)
12-
((<>) a11 a)
8+
(l_b7 <> l_b) (si8 <> si) (l_c9 <> l_c) (ea10 <> ea) (a11 <> a)
139

plugins/hls-tactics-plugin/test/golden/KnownCounterfactualSemigroup.hs.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ data Semi = Semi [String] Int
44

55
instance Semigroup Int => Semigroup Semi where
66
(<>) (Semi l_l_c5 i6) (Semi l_l_c i)
7-
= Semi ((<>) l_l_c5 l_l_c) ((<>) i6 i)
7+
= Semi (l_l_c5 <> l_l_c) (i6 <> i)
88

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
data Test a = Test [a]
22

33
instance Semigroup (Test a) where
4-
(<>) (Test a) (Test c) = Test ((<>) a c)
4+
(<>) (Test a) (Test c) = Test (a <> c)
55

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
data Semi = Semi [String] Int
22

33
instance Semigroup Semi where
4-
(<>) (Semi l_l_c4 i5) (Semi l_l_c i) = Semi ((<>) l_l_c4 l_l_c) _
4+
(<>) (Semi l_l_c4 i5) (Semi l_l_c i) = Semi (l_l_c4 <> l_l_c) _
55

plugins/hls-tactics-plugin/test/golden/KnownModuleInstanceSemigroup.hs.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ instance Semigroup Foo where
77
data Bar = Bar Foo Foo
88

99
instance Semigroup Bar where
10-
(<>) (Bar f4 f5) (Bar f f3) = Bar ((<>) f4 f) ((<>) f5 f3)
10+
(<>) (Bar f4 f5) (Bar f f3) = Bar (f4 <> f) (f5 <> f3)
1111

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
data Semi a = Semi a
22

33
instance Semigroup a => Semigroup (Semi a) where
4-
(<>) (Semi a4) (Semi a) = Semi ((<>) a4 a)
4+
(<>) (Semi a4) (Semi a) = Semi (a4 <> a)
55

0 commit comments

Comments
 (0)