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 <[email protected]>
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)

0 commit comments

Comments
 (0)