@@ -33,6 +33,7 @@ import Control.Monad.Trans.Writer.CPS
3333import Data.Data
3434import Data.Generics.Uniplate.DataOnly
3535import Data.List.Extra
36+ import Data.List.NonEmpty (NonEmpty (.. ), fromList , toList )
3637import Data.Tuple.Extra
3738import Data.Maybe
3839
@@ -57,7 +58,7 @@ dotApps (x : xs) = dotApp x (dotApps xs)
5758
5859-- | @lambda [p0, p1..pn] body@ makes @\p1 p1 .. pn -> body@
5960lambda :: [LPat GhcPs ] -> LHsExpr GhcPs -> LHsExpr GhcPs
60- lambda vs body = noLocA $ HsLam noAnn LamSingle (MG (Generated OtherExpansion DoPmc ) (noLocA [noLocA $ Match noExtField (LamAlt LamSingle ) (L noSpanAnchor vs) (GRHSs emptyComments [ noLocA $ GRHS noAnn [] body] (EmptyLocalBinds noExtField))]))
61+ lambda vs body = noLocA $ HsLam noAnn LamSingle (MG (Generated OtherExpansion DoPmc ) (noLocA [noLocA $ Match noExtField (LamAlt LamSingle ) (L noSpanAnchor vs) (GRHSs emptyComments ( noLocA ( GRHS noAnn [] body) :| [] ) (EmptyLocalBinds noExtField))]))
6162
6263-- | 'paren e' wraps 'e' in parens if 'e' is non-atomic.
6364paren :: LHsExpr GhcPs -> LHsExpr GhcPs
@@ -124,7 +125,7 @@ simplifyExp (L l (OpApp _ x op y)) | isDol op = L l (HsApp noExtField x (nlHsPar
124125simplifyExp e@ (L _ (HsLet _ ((HsValBinds _ (ValBinds _ binds [] ))) z)) =
125126 -- An expression of the form, 'let x = y in z'.
126127 case binds of
127- [L _ (FunBind _ _ (MG _ (L _ [L _ (Match _(FunRhs (L _ x) _ _ _) (L _ [] ) (GRHSs _ [ L _ (GRHS _ [] y)] ((EmptyLocalBinds _))))])))]
128+ [L _ (FunBind _ _ (MG _ (L _ [L _ (Match _(FunRhs (L _ x) _ _ _) (L _ [] ) (GRHSs _ ( L _ (GRHS _ [] y) :| [] ) ((EmptyLocalBinds _))))])))]
128129 -- If 'x' is not in the free variables of 'y', beta-reduce to
129130 -- 'z[(y)/x]'.
130131 | occNameStr x `notElem` vars y && length [() | Unqual a <- universeBi z, a == rdrNameOcc x] <= 1 ->
@@ -251,12 +252,11 @@ niceLambdaR parent = go
251252 -- Base case. Just a good old fashioned lambda.
252253 go ss e =
253254 let grhs = noLocA $ GRHS noAnn [] e :: LGRHS GhcPs (LHsExpr GhcPs )
254- grhss = GRHSs {grhssExt = emptyComments, grhssGRHSs= [grhs], grhssLocalBinds= EmptyLocalBinds noExtField}
255+ grhss = GRHSs {grhssExt = emptyComments, grhssGRHSs= fromList [grhs], grhssLocalBinds= EmptyLocalBinds noExtField}
255256 match = noLocA $ Match {m_ext= noExtField, m_ctxt= LamAlt LamSingle , m_pats= noLocA $ map strToPat ss, m_grhss= grhss} :: LMatch GhcPs (LHsExpr GhcPs )
256257 matchGroup = MG {mg_ext= Generated OtherExpansion SkipPmc , mg_alts= noLocA [match]}
257258 in (noLocA $ HsLam noAnn LamSingle matchGroup, const [] )
258259
259-
260260-- 'case' and 'if' expressions have branches, nothing else does (this
261261-- doesn't consider 'HsMultiIf' perhaps it should?).
262262replaceBranches :: LHsExpr GhcPs -> ([LHsExpr GhcPs ], [LHsExpr GhcPs ] -> LHsExpr GhcPs )
@@ -266,12 +266,12 @@ replaceBranches (L s (HsCase _ a (MG FromSource (L l bs)))) =
266266 (concatMap f bs, L s . HsCase noAnn a . MG (Generated OtherExpansion SkipPmc ). L l . g bs)
267267 where
268268 f :: LMatch GhcPs (LHsExpr GhcPs ) -> [LHsExpr GhcPs ]
269- f (L _ (Match _ CaseAlt _ (GRHSs _ xs _))) = [x | (L _ (GRHS _ _ x)) <- xs]
269+ f (L _ (Match _ CaseAlt _ (GRHSs _ xs _))) = [x | (L _ (GRHS _ _ x)) <- toList xs]
270270 f _ = error " GHC.Util.HsExpr.replaceBranches: unexpected XMatch"
271271
272272 g :: [LMatch GhcPs (LHsExpr GhcPs )] -> [LHsExpr GhcPs ] -> [LMatch GhcPs (LHsExpr GhcPs )]
273273 g (L s1 (Match _ CaseAlt a (GRHSs _ ns b)) : rest) xs =
274- L s1 (Match noExtField CaseAlt a (GRHSs emptyComments [L a (GRHS noAnn gs x) | (L a (GRHS _ gs _), x) <- zip ns as] b)) : g rest bs
274+ L s1 (Match noExtField CaseAlt a (GRHSs emptyComments (fromList [L a (GRHS noAnn gs x) | (L a (GRHS _ gs _), x) <- zip (toList ns) as]) b)) : g rest bs
275275 where (as, bs) = splitAt (length ns) xs
276276 g [] [] = []
277277 g _ _ = error " GHC.Util.HsExpr.replaceBranches': internal invariant failed, lists are of differing lengths"
0 commit comments