{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE ViewPatterns, PatternGuards, FlexibleContexts #-}
{-
    Find and match:

<TEST>
yes = 1:2:[] -- [1,2]
yes = ['h','e','l','l','o']
yes (1:2:[]) = 1 -- [1,2]
yes ['h','e'] = 1

-- [a]++b -> a : b, but only if not in a chain of ++'s
yes = [x] ++ xs -- x : xs
no = "x" ++ xs
no = [x] ++ xs ++ ys
no = xs ++ [x] ++ ys
yes = [if a then b else c] ++ xs -- (if a then b else c) : xs
yes = [1] : [2] : [3] : [4] : [5] : [] -- [[1], [2], [3], [4], [5]]
yes = if x == e then l2 ++ xs else [x] ++ check_elem xs -- x : check_elem xs
data Yes = Yes (Maybe [Char]) -- Maybe String
yes = y :: [Char] -> a -- String -> a
instance C [Char]
foo = [a b] ++ xs -- a b : xs
foo = [myexpr | True, a] -- [myexpr | a]
foo = [myexpr | False] -- []
foo = map f [x + 1 | x <- [1..10]] -- [f (x + 1) | x <- [1..10]]
foo = [x + 1 | x <- [1..10], feature] -- [x + 1 | feature, x <- [1..10]]
foo = [x + 1 | x <- [1..10], even x]
foo = [x + 1 | x <- [1..10], even x, dont_reoder_guards]
foo = [x + 1 | x <- [1..10], let y = even x, y]
foo = [x + 1 | x <- [1..10], let q = even 1, q] -- [x + 1 | let q = even 1, q, x <- [1..10]]
foo = [fooValue | Foo{..} <- y, fooField]
issue619 = [pkgJobs | Pkg{pkgGpd, pkgJobs} <- pkgs, not $ null $ C.condTestSuites pkgGpd]
{-# LANGUAGE MonadComprehensions #-}\
foo = [x | False, x <- [1 .. 10]] -- []
foo = [_ | x <- _, let _ = A{x}]
issue1039 = foo (map f [1 | _ <- []]) -- [f 1 | _ <- []]
{-# LANGUAGE OverloadedLists #-} \
issue114 = True:[]
</TEST>
-}

module Hint.List(listHint) where

import Control.Applicative
import Data.Generics.Uniplate.DataOnly
import Data.List.NonEmpty qualified as NE
import Data.List.Extra
import Data.Maybe
import Prelude

import Hint.Type(DeclHint,Idea,suggest,ignore,substVars,toRefactSrcSpan,toSSA,modComments,firstDeclComments)

import Refact.Types hiding (SrcSpan)
import Refact.Types qualified as R

import GHC.Hs
import GHC.Types.SrcLoc
import GHC.Types.SourceText
import GHC.Types.Name.Reader
import GHC.Data.FastString
import GHC.Builtin.Types

import GHC.Util
import Language.Haskell.GhclibParserEx.GHC.Hs.Pat
import Language.Haskell.GhclibParserEx.GHC.Hs.Expr
import Language.Haskell.GhclibParserEx.GHC.Hs.Type
import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances
import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable
import Language.Haskell.GhclibParserEx.GHC.Types.Name.Reader


listHint :: DeclHint
listHint :: DeclHint
listHint Scope
_ ModuleEx
modu = Bool -> LHsDecl GhcPs -> [Idea]
listDecl Bool
overloadedListsOn
  where
    -- Comments appearing without a line-break before the first
    -- declaration in a module are now associated with the declaration
    -- not the module so to be safe, look also at `firstDeclComments
    -- modu` (https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9517).
    exts :: [String]
exts = ((LEpaComment, [String]) -> [String])
-> [(LEpaComment, [String])] -> [String]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (LEpaComment, [String]) -> [String]
forall a b. (a, b) -> b
snd ([(LEpaComment, String)] -> [(LEpaComment, [String])]
languagePragmas (EpAnnComments -> [(LEpaComment, String)]
pragmas (ModuleEx -> EpAnnComments
modComments ModuleEx
modu) [(LEpaComment, String)]
-> [(LEpaComment, String)] -> [(LEpaComment, String)]
forall a. [a] -> [a] -> [a]
++ EpAnnComments -> [(LEpaComment, String)]
pragmas (ModuleEx -> EpAnnComments
firstDeclComments ModuleEx
modu)))
    overloadedListsOn :: Bool
overloadedListsOn = String
"OverloadedLists" String -> [String] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
exts

listDecl :: Bool -> LHsDecl GhcPs -> [Idea]
listDecl :: Bool -> LHsDecl GhcPs -> [Idea]
listDecl Bool
overloadedListsOn LHsDecl GhcPs
x =
  (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> [Idea])
-> [GenLocated SrcSpanAnnA (HsExpr GhcPs)] -> [Idea]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Bool -> Bool -> LHsExpr GhcPs -> [Idea]
listExp Bool
overloadedListsOn Bool
False) (GenLocated SrcSpanAnnA (HsDecl GhcPs)
-> [GenLocated SrcSpanAnnA (HsExpr GhcPs)]
forall from to. Biplate from to => from -> [to]
childrenBi LHsDecl GhcPs
GenLocated SrcSpanAnnA (HsDecl GhcPs)
x) [Idea] -> [Idea] -> [Idea]
forall a. [a] -> [a] -> [a]
++
  LHsDecl GhcPs -> [Idea]
stringType LHsDecl GhcPs
x [Idea] -> [Idea] -> [Idea]
forall a. [a] -> [a] -> [a]
++
  (GenLocated SrcSpanAnnA (Pat GhcPs) -> [Idea])
-> [GenLocated SrcSpanAnnA (Pat GhcPs)] -> [Idea]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap XRec GhcPs (Pat GhcPs) -> [Idea]
GenLocated SrcSpanAnnA (Pat GhcPs) -> [Idea]
listPat (GenLocated SrcSpanAnnA (HsDecl GhcPs)
-> [GenLocated SrcSpanAnnA (Pat GhcPs)]
forall from to. Biplate from to => from -> [to]
childrenBi LHsDecl GhcPs
GenLocated SrcSpanAnnA (HsDecl GhcPs)
x) [Idea] -> [Idea] -> [Idea]
forall a. [a] -> [a] -> [a]
++
  (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> [Idea])
-> [GenLocated SrcSpanAnnA (HsExpr GhcPs)] -> [Idea]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap LHsExpr GhcPs -> [Idea]
GenLocated SrcSpanAnnA (HsExpr GhcPs) -> [Idea]
listComp (GenLocated SrcSpanAnnA (HsDecl GhcPs)
-> [GenLocated SrcSpanAnnA (HsExpr GhcPs)]
forall from to. Biplate from to => from -> [to]
universeBi LHsDecl GhcPs
GenLocated SrcSpanAnnA (HsDecl GhcPs)
x)

-- Refer to https://github.com/ndmitchell/hlint/issues/775 for the
-- structure of 'listComp'.

listComp :: LHsExpr GhcPs -> [Idea]
listComp :: LHsExpr GhcPs -> [Idea]
listComp o :: LHsExpr GhcPs
o@(L SrcSpanAnnA
_ (HsDo XDo GhcPs
_ HsDoFlavour
ListComp (L SrcSpanAnnL
_ [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
stmts))) =
  LHsExpr GhcPs -> HsDoFlavour -> [ExprLStmt GhcPs] -> [Idea]
listCompCheckGuards LHsExpr GhcPs
o HsDoFlavour
ListComp [ExprLStmt GhcPs]
[GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
stmts
listComp o :: LHsExpr GhcPs
o@(L SrcSpanAnnA
_ (HsDo XDo GhcPs
_ HsDoFlavour
MonadComp (L SrcSpanAnnL
_ [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
stmts))) =
  LHsExpr GhcPs -> HsDoFlavour -> [ExprLStmt GhcPs] -> [Idea]
listCompCheckGuards LHsExpr GhcPs
o HsDoFlavour
MonadComp [ExprLStmt GhcPs]
[GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
stmts
listComp (L SrcSpanAnnA
_ HsPar{}) = [] -- App2 "sees through" paren, which causes duplicate hints with universeBi
listComp o :: LHsExpr GhcPs
o@(LHsExpr GhcPs -> App2
GenLocated SrcSpanAnnA (HsExpr GhcPs) -> App2
forall a b. View a b => a -> b
view -> App2 GenLocated SrcSpanAnnA (HsExpr GhcPs)
mp GenLocated SrcSpanAnnA (HsExpr GhcPs)
f (L SrcSpanAnnA
_ (HsDo XDo GhcPs
_ HsDoFlavour
ListComp (L SrcSpanAnnL
_ [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
stmts)))) =
  LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> HsDoFlavour
-> [ExprLStmt GhcPs]
-> [Idea]
listCompCheckMap LHsExpr GhcPs
o LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
mp LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
f HsDoFlavour
ListComp [ExprLStmt GhcPs]
[GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
stmts
listComp o :: LHsExpr GhcPs
o@(LHsExpr GhcPs -> App2
GenLocated SrcSpanAnnA (HsExpr GhcPs) -> App2
forall a b. View a b => a -> b
view -> App2 GenLocated SrcSpanAnnA (HsExpr GhcPs)
mp GenLocated SrcSpanAnnA (HsExpr GhcPs)
f (L SrcSpanAnnA
_ (HsDo XDo GhcPs
_ HsDoFlavour
MonadComp (L SrcSpanAnnL
_ [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
stmts)))) =
  LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> HsDoFlavour
-> [ExprLStmt GhcPs]
-> [Idea]
listCompCheckMap LHsExpr GhcPs
o LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
mp LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
f HsDoFlavour
MonadComp [ExprLStmt GhcPs]
[GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
stmts
listComp LHsExpr GhcPs
_ = []

listCompCheckGuards :: LHsExpr GhcPs -> HsDoFlavour -> [ExprLStmt GhcPs] -> [Idea]
listCompCheckGuards :: LHsExpr GhcPs -> HsDoFlavour -> [ExprLStmt GhcPs] -> [Idea]
listCompCheckGuards LHsExpr GhcPs
o HsDoFlavour
ctx [ExprLStmt GhcPs]
stmts =
  let revs :: NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
revs = NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
-> NonEmpty
     (GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
forall a. NonEmpty a -> NonEmpty a
NE.reverse (NonEmpty
   (GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
 -> NonEmpty
      (GenLocated
         SrcSpanAnnA
         (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))))
-> NonEmpty
     (GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
-> NonEmpty
     (GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
forall a b. (a -> b) -> a -> b
$ [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> NonEmpty
     (GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
forall a. HasCallStack => [a] -> NonEmpty a
NE.fromList [ExprLStmt GhcPs]
[GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
stmts
      e :: GenLocated
  SrcSpanAnnA
  (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
e@(L SrcSpanAnnA
_ LastStmt{}) = NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
-> GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
forall a. NonEmpty a -> a
NE.head NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
revs -- In a ListComp, this is always last.
      xs :: [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
xs = [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. [a] -> [a]
reverse (NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. NonEmpty a -> [a]
NE.tail NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
revs) in
  GenLocated
  SrcSpanAnnA
  (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [Idea]
list_comp_aux GenLocated
  SrcSpanAnnA
  (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
e [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
xs
  where
    list_comp_aux :: GenLocated
  SrcSpanAnnA
  (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [Idea]
list_comp_aux GenLocated
  SrcSpanAnnA
  (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
e [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
xs
      | String
"False" String -> [String] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
cons =  [String
-> Located (HsExpr GhcPs)
-> Located (HsExpr GhcPs)
-> [Refactoring SrcSpan]
-> Idea
forall a b.
(Outputable a, Outputable b) =>
String -> Located a -> Located b -> [Refactoring SrcSpan] -> Idea
suggest String
"Short-circuited list comprehension" (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Located (HsExpr GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
o) (LocatedAn Any (HsExpr GhcPs) -> Located (HsExpr GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc LocatedAn Any (HsExpr GhcPs)
forall {an}. LocatedAn an (HsExpr GhcPs)
o') (LHsExpr GhcPs -> LHsExpr GhcPs -> [Refactoring SrcSpan]
suggestExpr LHsExpr GhcPs
o LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall {an}. LocatedAn an (HsExpr GhcPs)
o')]
      | String
"True" String -> [String] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
cons = [String
-> Located (HsExpr GhcPs)
-> Located (HsExpr GhcPs)
-> [Refactoring SrcSpan]
-> Idea
forall a b.
(Outputable a, Outputable b) =>
String -> Located a -> Located b -> [Refactoring SrcSpan] -> Idea
suggest String
"Redundant True guards" (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Located (HsExpr GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
o) (LocatedAn Any (HsExpr GhcPs) -> Located (HsExpr GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc LocatedAn Any (HsExpr GhcPs)
forall {an}. LocatedAn an (HsExpr GhcPs)
o2) (LHsExpr GhcPs -> LHsExpr GhcPs -> [Refactoring SrcSpan]
suggestExpr LHsExpr GhcPs
o LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall {an}. LocatedAn an (HsExpr GhcPs)
o2)]
      | Bool -> Bool
not ([GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> Bool
forall a. Data a => [a] -> [a] -> Bool
astListEq [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
xs [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
ys) = [String
-> Located (HsExpr GhcPs)
-> Located (HsExpr GhcPs)
-> [Refactoring SrcSpan]
-> Idea
forall a b.
(Outputable a, Outputable b) =>
String -> Located a -> Located b -> [Refactoring SrcSpan] -> Idea
suggest String
"Move guards forward" (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Located (HsExpr GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
o) (LocatedAn Any (HsExpr GhcPs) -> Located (HsExpr GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc LocatedAn Any (HsExpr GhcPs)
forall {an}. LocatedAn an (HsExpr GhcPs)
o3) (LHsExpr GhcPs -> LHsExpr GhcPs -> [Refactoring SrcSpan]
suggestExpr LHsExpr GhcPs
o LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall {an}. LocatedAn an (HsExpr GhcPs)
o3)]
      | Bool
otherwise = []
      where
        ys :: [ExprLStmt GhcPs]
ys = [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
moveGuardsForward [ExprLStmt GhcPs]
[GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
xs
        o' :: LocatedAn an (HsExpr GhcPs)
o' = HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs)
forall a an. a -> LocatedAn an a
noLocA (HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs))
-> HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XExplicitList GhcPs -> [LHsExpr GhcPs] -> HsExpr GhcPs
forall p. XExplicitList p -> [LHsExpr p] -> HsExpr p
ExplicitList XExplicitList GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed []
        o2 :: LocatedAn an (HsExpr GhcPs)
o2 = HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs)
forall a an. a -> LocatedAn an a
noLocA (HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs))
-> HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XDo GhcPs
-> HsDoFlavour -> XRec GhcPs [ExprLStmt GhcPs] -> HsExpr GhcPs
forall p. XDo p -> HsDoFlavour -> XRec p [ExprLStmt p] -> HsExpr p
HsDo XDo GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed HsDoFlavour
ctx ([GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> GenLocated
     SrcSpanAnnL
     [GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a an. a -> LocatedAn an a
noLocA ((GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
 -> Bool)
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Maybe String -> Maybe String -> Bool
forall a. Eq a => a -> a -> Bool
/= String -> Maybe String
forall a. a -> Maybe a
Just String
"True") (Maybe String -> Bool)
-> (GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
    -> Maybe String)
-> GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExprLStmt GhcPs -> Maybe String
GenLocated
  SrcSpanAnnA
  (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
-> Maybe String
qualCon) [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
xs [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. [a] -> [a] -> [a]
++ [GenLocated
  SrcSpanAnnA
  (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
e]))
        o3 :: LocatedAn an (HsExpr GhcPs)
o3 = HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs)
forall a an. a -> LocatedAn an a
noLocA (HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs))
-> HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XDo GhcPs
-> HsDoFlavour -> XRec GhcPs [ExprLStmt GhcPs] -> HsExpr GhcPs
forall p. XDo p -> HsDoFlavour -> XRec p [ExprLStmt p] -> HsExpr p
HsDo XDo GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed HsDoFlavour
ctx ([GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> GenLocated
     SrcSpanAnnL
     [GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a an. a -> LocatedAn an a
noLocA ([GenLocated
    SrcSpanAnnA
    (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
 -> GenLocated
      SrcSpanAnnL
      [GenLocated
         SrcSpanAnnA
         (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))])
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> GenLocated
     SrcSpanAnnL
     [GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a b. (a -> b) -> a -> b
$ [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
ys [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. [a] -> [a] -> [a]
++ [GenLocated
  SrcSpanAnnA
  (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
e])
        cons :: [String]
cons = (GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
 -> Maybe String)
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [String]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe ExprLStmt GhcPs -> Maybe String
GenLocated
  SrcSpanAnnA
  (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
-> Maybe String
qualCon [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
xs
        qualCon :: ExprLStmt GhcPs -> Maybe String
        qualCon :: ExprLStmt GhcPs -> Maybe String
qualCon (L SrcSpanAnnA
_ (BodyStmt XBodyStmt GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
_ (L SrcSpanAnnA
_ (HsVar XVar GhcPs
_ (L SrcSpanAnnN
_ RdrName
x))) SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_)) = String -> Maybe String
forall a. a -> Maybe a
Just (RdrName -> String
occNameStr RdrName
x)
        qualCon ExprLStmt GhcPs
_ = Maybe String
forall a. Maybe a
Nothing

listCompCheckMap ::
  LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsDoFlavour -> [ExprLStmt GhcPs] -> [Idea]
listCompCheckMap :: LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> HsDoFlavour
-> [ExprLStmt GhcPs]
-> [Idea]
listCompCheckMap LHsExpr GhcPs
o LHsExpr GhcPs
mp LHsExpr GhcPs
f HsDoFlavour
ctx [ExprLStmt GhcPs]
stmts  | LHsExpr GhcPs -> String
varToStr LHsExpr GhcPs
mp String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"map" =
    [String
-> Located (HsExpr GhcPs)
-> Located (HsExpr GhcPs)
-> [Refactoring SrcSpan]
-> Idea
forall a b.
(Outputable a, Outputable b) =>
String -> Located a -> Located b -> [Refactoring SrcSpan] -> Idea
suggest String
"Move map inside list comprehension" (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Located (HsExpr GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
o) (LocatedAn Any (HsExpr GhcPs) -> Located (HsExpr GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc LocatedAn Any (HsExpr GhcPs)
forall {an}. LocatedAn an (HsExpr GhcPs)
o2) (LHsExpr GhcPs -> LHsExpr GhcPs -> [Refactoring SrcSpan]
suggestExpr LHsExpr GhcPs
o LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall {an}. LocatedAn an (HsExpr GhcPs)
o2)]
    where
      revs :: NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
revs = NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
-> NonEmpty
     (GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
forall a. NonEmpty a -> NonEmpty a
NE.reverse (NonEmpty
   (GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
 -> NonEmpty
      (GenLocated
         SrcSpanAnnA
         (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))))
-> NonEmpty
     (GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
-> NonEmpty
     (GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
forall a b. (a -> b) -> a -> b
$ [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> NonEmpty
     (GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
forall a. HasCallStack => [a] -> NonEmpty a
NE.fromList [ExprLStmt GhcPs]
[GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
stmts
      L SrcSpanAnnA
_ (LastStmt XLastStmt GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
_ GenLocated SrcSpanAnnA (HsExpr GhcPs)
body Maybe Bool
b SyntaxExpr GhcPs
s) = NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
-> GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
forall a. NonEmpty a -> a
NE.head NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
revs -- In a ListComp, this is always last.
      last :: LocatedAn
  an (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
last = StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
-> LocatedAn
     an (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
forall a an. a -> LocatedAn an a
noLocA (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
 -> LocatedAn
      an (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
-> StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
-> LocatedAn
     an (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
forall a b. (a -> b) -> a -> b
$ XLastStmt GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe Bool
-> SyntaxExpr GhcPs
-> StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
forall idL idR body.
XLastStmt idL idR body
-> body -> Maybe Bool -> SyntaxExpr idR -> StmtLR idL idR body
LastStmt XLastStmt GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
NoExtField
noExtField (HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a an. a -> LocatedAn an a
noLocA (HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs))
-> HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XApp GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp GhcPs
EpAnn NoEpAnns
forall ann. EpAnn ann
EpAnnNotUsed (LHsExpr GhcPs -> LHsExpr GhcPs
paren LHsExpr GhcPs
f) (LHsExpr GhcPs -> LHsExpr GhcPs
paren LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
body)) Maybe Bool
b NoExtField
SyntaxExpr GhcPs
s
      o2 :: LocatedAn an (HsExpr GhcPs)
o2 =HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs)
forall a an. a -> LocatedAn an a
noLocA (HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs))
-> HsExpr GhcPs -> LocatedAn an (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XDo GhcPs
-> HsDoFlavour -> XRec GhcPs [ExprLStmt GhcPs] -> HsExpr GhcPs
forall p. XDo p -> HsDoFlavour -> XRec p [ExprLStmt p] -> HsExpr p
HsDo XDo GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed HsDoFlavour
ctx ([GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> GenLocated
     SrcSpanAnnL
     [GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a an. a -> LocatedAn an a
noLocA ([GenLocated
    SrcSpanAnnA
    (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
 -> GenLocated
      SrcSpanAnnL
      [GenLocated
         SrcSpanAnnA
         (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))])
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> GenLocated
     SrcSpanAnnL
     [GenLocated
        SrcSpanAnnA
        (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a b. (a -> b) -> a -> b
$ [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. [a] -> [a]
reverse (NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. NonEmpty a -> [a]
NE.tail NonEmpty
  (GenLocated
     SrcSpanAnnA
     (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
revs) [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. [a] -> [a] -> [a]
++ [GenLocated
  SrcSpanAnnA
  (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
forall {an}.
LocatedAn
  an (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
last])
listCompCheckMap LHsExpr GhcPs
_ LHsExpr GhcPs
_ LHsExpr GhcPs
_ HsDoFlavour
_ [ExprLStmt GhcPs]
_ = []

suggestExpr :: LHsExpr GhcPs -> LHsExpr GhcPs -> [Refactoring R.SrcSpan]
suggestExpr :: LHsExpr GhcPs -> LHsExpr GhcPs -> [Refactoring SrcSpan]
suggestExpr LHsExpr GhcPs
o LHsExpr GhcPs
o2 = [RType
-> SrcSpan -> [(String, SrcSpan)] -> String -> Refactoring SrcSpan
forall a. RType -> a -> [(String, a)] -> String -> Refactoring a
Replace RType
Expr (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
toSSA LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
o) [] (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> String
forall a. Outputable a => a -> String
unsafePrettyPrint LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
o2)]

moveGuardsForward :: [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
moveGuardsForward :: [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
moveGuardsForward = [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. [a] -> [a]
reverse ([GenLocated
    SrcSpanAnnA
    (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
 -> [GenLocated
       SrcSpanAnnA
       (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))])
-> ([GenLocated
       SrcSpanAnnA
       (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
    -> [GenLocated
          SrcSpanAnnA
          (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))])
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall {l} {idL} {idR} {body}.
(Data l, Data (StmtLR idL idR body), Typeable idL, Typeable idR,
 Typeable body, AllVars (GenLocated l (StmtLR idL idR body)),
 AllVars (XRec idL (Pat idL))) =>
[GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
f [] ([GenLocated
    SrcSpanAnnA
    (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
 -> [GenLocated
       SrcSpanAnnA
       (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))])
-> ([GenLocated
       SrcSpanAnnA
       (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
    -> [GenLocated
          SrcSpanAnnA
          (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))])
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GenLocated
   SrcSpanAnnA
   (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [GenLocated
      SrcSpanAnnA
      (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. [a] -> [a]
reverse
  where
    f :: [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
f [GenLocated l (StmtLR idL idR body)]
guards (x :: GenLocated l (StmtLR idL idR body)
x@(L l
_ (BindStmt XBindStmt idL idR body
_ XRec idL (Pat idL)
p body
_)) : [GenLocated l (StmtLR idL idR body)]
xs) = [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
forall a. [a] -> [a]
reverse [GenLocated l (StmtLR idL idR body)]
stop [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
forall a. [a] -> [a] -> [a]
++ GenLocated l (StmtLR idL idR body)
x GenLocated l (StmtLR idL idR body)
-> [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
forall a. a -> [a] -> [a]
: [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
f [GenLocated l (StmtLR idL idR body)]
move [GenLocated l (StmtLR idL idR body)]
xs
      where ([GenLocated l (StmtLR idL idR body)]
move, [GenLocated l (StmtLR idL idR body)]
stop) =
              (GenLocated l (StmtLR idL idR body) -> Bool)
-> [GenLocated l (StmtLR idL idR body)]
-> ([GenLocated l (StmtLR idL idR body)],
    [GenLocated l (StmtLR idL idR body)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (if (HsRecFields GhcPs (GenLocated SrcSpanAnnA (Pat GhcPs)) -> Bool)
-> [HsRecFields GhcPs (GenLocated SrcSpanAnnA (Pat GhcPs))] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any HsRecFields GhcPs (XRec GhcPs (Pat GhcPs)) -> Bool
HsRecFields GhcPs (GenLocated SrcSpanAnnA (Pat GhcPs)) -> Bool
hasPFieldsDotDot (GenLocated l (StmtLR idL idR body)
-> [HsRecFields GhcPs (GenLocated SrcSpanAnnA (Pat GhcPs))]
forall from to. Biplate from to => from -> [to]
universeBi GenLocated l (StmtLR idL idR body)
x)
                       Bool -> Bool -> Bool
|| (GenLocated
   SrcSpanAnnA
   (HsFieldBind
      (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
      (GenLocated SrcSpanAnnA (Pat GhcPs)))
 -> Bool)
-> [GenLocated
      SrcSpanAnnA
      (HsFieldBind
         (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
         (GenLocated SrcSpanAnnA (Pat GhcPs)))]
-> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any LHsFieldBind GhcPs (LFieldOcc GhcPs) (XRec GhcPs (Pat GhcPs))
-> Bool
GenLocated
  SrcSpanAnnA
  (HsFieldBind
     (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
     (GenLocated SrcSpanAnnA (Pat GhcPs)))
-> Bool
isPFieldWildcard (GenLocated l (StmtLR idL idR body)
-> [GenLocated
      SrcSpanAnnA
      (HsFieldBind
         (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
         (GenLocated SrcSpanAnnA (Pat GhcPs)))]
forall from to. Biplate from to => from -> [to]
universeBi GenLocated l (StmtLR idL idR body)
x)
                      then Bool -> GenLocated l (StmtLR idL idR body) -> Bool
forall a b. a -> b -> a
const Bool
False
                      else \GenLocated l (StmtLR idL idR body)
x ->
                       let pvs :: [String]
pvs = XRec idL (Pat idL) -> [String]
forall a. AllVars a => a -> [String]
pvars XRec idL (Pat idL)
p in
                       -- See this code from 'RdrHsSyn.hs' (8.10.1):
                       --   plus_RDR, pun_RDR :: RdrName
                       --   plus_RDR = mkUnqual varName (fsLit "+") -- Hack
                       --   pun_RDR  = mkUnqual varName (fsLit "pun-right-hand-side")
                       -- Todo (SF, 2020-03-28): Try to make this better somehow.
                       [String]
pvs [String] -> [String] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`disjoint` GenLocated l (StmtLR idL idR body) -> [String]
forall a. AllVars a => a -> [String]
varss GenLocated l (StmtLR idL idR body)
x Bool -> Bool -> Bool
&& String
"pun-right-hand-side" String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [String]
pvs
                   ) [GenLocated l (StmtLR idL idR body)]
guards
    f [GenLocated l (StmtLR idL idR body)]
guards (x :: GenLocated l (StmtLR idL idR body)
x@(L l
_ BodyStmt{}):[GenLocated l (StmtLR idL idR body)]
xs) = [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
f (GenLocated l (StmtLR idL idR body)
xGenLocated l (StmtLR idL idR body)
-> [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
forall a. a -> [a] -> [a]
:[GenLocated l (StmtLR idL idR body)]
guards) [GenLocated l (StmtLR idL idR body)]
xs
    f [GenLocated l (StmtLR idL idR body)]
guards (x :: GenLocated l (StmtLR idL idR body)
x@(L l
_ LetStmt{}):[GenLocated l (StmtLR idL idR body)]
xs) = [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
f (GenLocated l (StmtLR idL idR body)
xGenLocated l (StmtLR idL idR body)
-> [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
forall a. a -> [a] -> [a]
:[GenLocated l (StmtLR idL idR body)]
guards) [GenLocated l (StmtLR idL idR body)]
xs
    f [GenLocated l (StmtLR idL idR body)]
guards [GenLocated l (StmtLR idL idR body)]
xs = [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
forall a. [a] -> [a]
reverse [GenLocated l (StmtLR idL idR body)]
guards [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
-> [GenLocated l (StmtLR idL idR body)]
forall a. [a] -> [a] -> [a]
++ [GenLocated l (StmtLR idL idR body)]
xs

listExp :: Bool -> Bool -> LHsExpr GhcPs -> [Idea]
listExp :: Bool -> Bool -> LHsExpr GhcPs -> [Idea]
listExp Bool
overloadedListsOn Bool
b (LHsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
fromParen -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
x) =
  if [Idea] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Idea]
res
    then (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> [Idea])
-> [GenLocated SrcSpanAnnA (HsExpr GhcPs)] -> [Idea]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Bool -> Bool -> LHsExpr GhcPs -> [Idea]
listExp Bool
overloadedListsOn (Bool -> LHsExpr GhcPs -> [Idea])
-> Bool -> LHsExpr GhcPs -> [Idea]
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Bool
forall a. View a App2 => a -> Bool
isAppend GenLocated SrcSpanAnnA (HsExpr GhcPs)
x) ([GenLocated SrcSpanAnnA (HsExpr GhcPs)] -> [Idea])
-> [GenLocated SrcSpanAnnA (HsExpr GhcPs)] -> [Idea]
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> [GenLocated SrcSpanAnnA (HsExpr GhcPs)]
forall on. Uniplate on => on -> [on]
children GenLocated SrcSpanAnnA (HsExpr GhcPs)
x
    else [NonEmpty Idea -> Idea
forall a. NonEmpty a -> a
NE.head (NonEmpty Idea -> Idea) -> NonEmpty Idea -> Idea
forall a b. (a -> b) -> a -> b
$ [Idea] -> NonEmpty Idea
forall a. HasCallStack => [a] -> NonEmpty a
NE.fromList [Idea]
res]
  where
    res :: [Idea]
res = [String
-> Located (HsExpr GhcPs)
-> Located (HsExpr GhcPs)
-> [Refactoring SrcSpan]
-> Idea
forall a b.
(Outputable a, Outputable b) =>
String -> Located a -> Located b -> [Refactoring SrcSpan] -> Idea
suggest String
name (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Located (HsExpr GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc GenLocated SrcSpanAnnA (HsExpr GhcPs)
x) (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Located (HsExpr GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc GenLocated SrcSpanAnnA (HsExpr GhcPs)
x2) [Refactoring SrcSpan
r]
          | (String
name, Bool
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
      String)
f) <- Bool
-> [(String,
     Bool
     -> LHsExpr GhcPs
     -> Maybe (LHsExpr GhcPs, [(String, SrcSpan)], String))]
checks Bool
overloadedListsOn
          , Just (GenLocated SrcSpanAnnA (HsExpr GhcPs)
x2, [(String, SrcSpan)]
subts, String
temp) <- [Bool
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
      String)
f Bool
b GenLocated SrcSpanAnnA (HsExpr GhcPs)
x]
          , let r :: Refactoring SrcSpan
r = RType
-> SrcSpan -> [(String, SrcSpan)] -> String -> Refactoring SrcSpan
forall a. RType -> a -> [(String, a)] -> String -> Refactoring a
Replace RType
Expr (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
toSSA GenLocated SrcSpanAnnA (HsExpr GhcPs)
x) [(String, SrcSpan)]
subts String
temp ]

listPat :: LPat GhcPs -> [Idea]
listPat :: XRec GhcPs (Pat GhcPs) -> [Idea]
listPat XRec GhcPs (Pat GhcPs)
x = if [Idea] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Idea]
res then (GenLocated SrcSpanAnnA (Pat GhcPs) -> [Idea])
-> [GenLocated SrcSpanAnnA (Pat GhcPs)] -> [Idea]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap XRec GhcPs (Pat GhcPs) -> [Idea]
GenLocated SrcSpanAnnA (Pat GhcPs) -> [Idea]
listPat ([GenLocated SrcSpanAnnA (Pat GhcPs)] -> [Idea])
-> [GenLocated SrcSpanAnnA (Pat GhcPs)] -> [Idea]
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (Pat GhcPs)
-> [GenLocated SrcSpanAnnA (Pat GhcPs)]
forall on. Uniplate on => on -> [on]
children XRec GhcPs (Pat GhcPs)
GenLocated SrcSpanAnnA (Pat GhcPs)
x else [NonEmpty Idea -> Idea
forall a. NonEmpty a -> a
NE.head (NonEmpty Idea -> Idea) -> NonEmpty Idea -> Idea
forall a b. (a -> b) -> a -> b
$ [Idea] -> NonEmpty Idea
forall a. HasCallStack => [a] -> NonEmpty a
NE.fromList [Idea]
res]
    where res :: [Idea]
res = [String
-> Located (Pat GhcPs)
-> Located (Pat GhcPs)
-> [Refactoring SrcSpan]
-> Idea
forall a b.
(Outputable a, Outputable b) =>
String -> Located a -> Located b -> [Refactoring SrcSpan] -> Idea
suggest String
name (GenLocated SrcSpanAnnA (Pat GhcPs) -> Located (Pat GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc XRec GhcPs (Pat GhcPs)
GenLocated SrcSpanAnnA (Pat GhcPs)
x) (GenLocated SrcSpanAnnA (Pat GhcPs) -> Located (Pat GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc GenLocated SrcSpanAnnA (Pat GhcPs)
x2) [Refactoring SrcSpan
r]
                  | (String
name, GenLocated SrcSpanAnnA (Pat GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String)
f) <- [(String,
  XRec GhcPs (Pat GhcPs)
  -> Maybe (XRec GhcPs (Pat GhcPs), [(String, SrcSpan)], String))]
[(String,
  GenLocated SrcSpanAnnA (Pat GhcPs)
  -> Maybe
       (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String))]
pchecks
                  , Just (GenLocated SrcSpanAnnA (Pat GhcPs)
x2, [(String, SrcSpan)]
subts, String
temp) <- [GenLocated SrcSpanAnnA (Pat GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String)
f XRec GhcPs (Pat GhcPs)
GenLocated SrcSpanAnnA (Pat GhcPs)
x]
                  , let r :: Refactoring SrcSpan
r = RType
-> SrcSpan -> [(String, SrcSpan)] -> String -> Refactoring SrcSpan
forall a. RType -> a -> [(String, a)] -> String -> Refactoring a
Replace RType
Pattern (GenLocated SrcSpanAnnA (Pat GhcPs) -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
toSSA XRec GhcPs (Pat GhcPs)
GenLocated SrcSpanAnnA (Pat GhcPs)
x) [(String, SrcSpan)]
subts String
temp ]

isAppend :: View a App2 => a -> Bool
isAppend :: forall a. View a App2 => a -> Bool
isAppend (a -> App2
forall a b. View a b => a -> b
view -> App2 GenLocated SrcSpanAnnA (HsExpr GhcPs)
op GenLocated SrcSpanAnnA (HsExpr GhcPs)
_ GenLocated SrcSpanAnnA (HsExpr GhcPs)
_) = LHsExpr GhcPs -> String
varToStr LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
op String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"++"
isAppend a
_ = Bool
False

checks :: Bool -> [(String, Bool -> LHsExpr GhcPs -> Maybe (LHsExpr GhcPs, [(String, R.SrcSpan)], String))]
checks :: Bool
-> [(String,
     Bool
     -> LHsExpr GhcPs
     -> Maybe (LHsExpr GhcPs, [(String, SrcSpan)], String))]
checks Bool
overloadedListsOn = let * :: a -> b -> (a, b)
(*) = (,) in [(String,
  Bool
  -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
  -> Maybe
       (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
        String))]
-> [(String,
     Bool
     -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
     -> Maybe
          (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
           String))]
forall a. [a] -> [a]
drop1 -- see #174
  [ String
"Use string literal" String
-> (Bool
    -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
    -> Maybe
         (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
          String))
-> (String,
    Bool
    -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
    -> Maybe
         (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
          String))
forall a b. a -> b -> (a, b)
* Bool
-> LHsExpr GhcPs
-> Maybe (LHsExpr GhcPs, [(String, SrcSpan)], String)
Bool
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
      String)
forall p a.
p -> LHsExpr GhcPs -> Maybe (LHsExpr GhcPs, [a], String)
useString
  , String
"Use :" String
-> (Bool
    -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
    -> Maybe
         (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
          String))
-> (String,
    Bool
    -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
    -> Maybe
         (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
          String))
forall a b. a -> b -> (a, b)
* Bool
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe (LHsExpr GhcPs, [(String, SrcSpan)], String)
Bool
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
      String)
forall a.
View a App2 =>
Bool -> a -> Maybe (LHsExpr GhcPs, [(String, SrcSpan)], String)
useCons
  ]
  [(String,
  Bool
  -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
  -> Maybe
       (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
        String))]
-> [(String,
     Bool
     -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
     -> Maybe
          (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
           String))]
-> [(String,
     Bool
     -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
     -> Maybe
          (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
           String))]
forall a. Semigroup a => a -> a -> a
<> [String
"Use list literal" String
-> (Bool
    -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
    -> Maybe
         (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
          String))
-> (String,
    Bool
    -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
    -> Maybe
         (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
          String))
forall a b. a -> b -> (a, b)
* Bool
-> LHsExpr GhcPs
-> Maybe (LHsExpr GhcPs, [(String, SrcSpan)], String)
Bool
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
      String)
forall p.
p
-> LHsExpr GhcPs
-> Maybe (LHsExpr GhcPs, [(String, SrcSpan)], String)
useList | Bool -> Bool
not Bool
overloadedListsOn ] -- see #114

pchecks :: [(String, LPat GhcPs -> Maybe (LPat GhcPs, [(String, R.SrcSpan)], String))]
pchecks :: [(String,
  XRec GhcPs (Pat GhcPs)
  -> Maybe (XRec GhcPs (Pat GhcPs), [(String, SrcSpan)], String))]
pchecks = let * :: a -> b -> (a, b)
(*) = (,) in [(String,
  GenLocated SrcSpanAnnA (Pat GhcPs)
  -> Maybe
       (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String))]
-> [(String,
     GenLocated SrcSpanAnnA (Pat GhcPs)
     -> Maybe
          (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String))]
forall a. [a] -> [a]
drop1 -- see #174
    [ String
"Use string literal pattern" String
-> (GenLocated SrcSpanAnnA (Pat GhcPs)
    -> Maybe
         (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String))
-> (String,
    GenLocated SrcSpanAnnA (Pat GhcPs)
    -> Maybe
         (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String))
forall a b. a -> b -> (a, b)
* XRec GhcPs (Pat GhcPs)
-> Maybe (XRec GhcPs (Pat GhcPs), [(String, SrcSpan)], String)
GenLocated SrcSpanAnnA (Pat GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String)
forall a.
XRec GhcPs (Pat GhcPs)
-> Maybe (XRec GhcPs (Pat GhcPs), [a], String)
usePString
    , String
"Use list literal pattern" String
-> (GenLocated SrcSpanAnnA (Pat GhcPs)
    -> Maybe
         (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String))
-> (String,
    GenLocated SrcSpanAnnA (Pat GhcPs)
    -> Maybe
         (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String))
forall a b. a -> b -> (a, b)
* XRec GhcPs (Pat GhcPs)
-> Maybe (XRec GhcPs (Pat GhcPs), [(String, SrcSpan)], String)
GenLocated SrcSpanAnnA (Pat GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String)
usePList
    ]

usePString :: LPat GhcPs -> Maybe (LPat GhcPs, [a], String)
usePString :: forall a.
XRec GhcPs (Pat GhcPs)
-> Maybe (XRec GhcPs (Pat GhcPs), [a], String)
usePString (L SrcSpanAnnA
_ (ListPat XListPat GhcPs
_ [XRec GhcPs (Pat GhcPs)]
xs)) | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [GenLocated SrcSpanAnnA (Pat GhcPs)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [XRec GhcPs (Pat GhcPs)]
[GenLocated SrcSpanAnnA (Pat GhcPs)]
xs, Just String
s <- (GenLocated SrcSpanAnnA (Pat GhcPs) -> Maybe Char)
-> [GenLocated SrcSpanAnnA (Pat GhcPs)] -> Maybe String
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM XRec GhcPs (Pat GhcPs) -> Maybe Char
GenLocated SrcSpanAnnA (Pat GhcPs) -> Maybe Char
fromPChar [XRec GhcPs (Pat GhcPs)]
[GenLocated SrcSpanAnnA (Pat GhcPs)]
xs =
  let literal :: XRec GhcPs (Pat GhcPs)
literal = Pat GhcPs -> GenLocated SrcSpanAnnA (Pat GhcPs)
forall a an. a -> LocatedAn an a
noLocA (Pat GhcPs -> GenLocated SrcSpanAnnA (Pat GhcPs))
-> Pat GhcPs -> GenLocated SrcSpanAnnA (Pat GhcPs)
forall a b. (a -> b) -> a -> b
$ XLitPat GhcPs -> HsLit GhcPs -> Pat GhcPs
forall p. XLitPat p -> HsLit p -> Pat p
LitPat XLitPat GhcPs
NoExtField
noExtField (XHsString GhcPs -> FastString -> HsLit GhcPs
forall x. XHsString x -> FastString -> HsLit x
HsString XHsString GhcPs
SourceText
NoSourceText (String -> FastString
fsLit (String -> String
forall a. Show a => a -> String
show String
s))) :: LPat GhcPs
  in (GenLocated SrcSpanAnnA (Pat GhcPs), [a], String)
-> Maybe (GenLocated SrcSpanAnnA (Pat GhcPs), [a], String)
forall a. a -> Maybe a
Just (GenLocated SrcSpanAnnA (Pat GhcPs)
literal, [], GenLocated SrcSpanAnnA (Pat GhcPs) -> String
forall a. Outputable a => a -> String
unsafePrettyPrint GenLocated SrcSpanAnnA (Pat GhcPs)
literal)
usePString XRec GhcPs (Pat GhcPs)
_ = Maybe (XRec GhcPs (Pat GhcPs), [a], String)
Maybe (GenLocated SrcSpanAnnA (Pat GhcPs), [a], String)
forall a. Maybe a
Nothing

usePList :: LPat GhcPs -> Maybe (LPat GhcPs, [(String, R.SrcSpan)], String)
usePList :: XRec GhcPs (Pat GhcPs)
-> Maybe (XRec GhcPs (Pat GhcPs), [(String, SrcSpan)], String)
usePList =
  ([(GenLocated SrcSpanAnnA (Pat GhcPs),
   ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
 -> (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)],
     String))
-> Maybe
     [(GenLocated SrcSpanAnnA (Pat GhcPs),
       ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
-> Maybe
     (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap  ( (\([GenLocated SrcSpanAnnA (Pat GhcPs)]
e, [((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))]
s) ->
             (Pat GhcPs -> GenLocated SrcSpanAnnA (Pat GhcPs)
forall a an. a -> LocatedAn an a
noLocA (XListPat GhcPs -> [XRec GhcPs (Pat GhcPs)] -> Pat GhcPs
forall p. XListPat p -> [LPat p] -> Pat p
ListPat XListPat GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed [XRec GhcPs (Pat GhcPs)]
[GenLocated SrcSpanAnnA (Pat GhcPs)]
e)
             , (((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))
 -> (String, SrcSpan))
-> [((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))]
-> [(String, SrcSpan)]
forall a b. (a -> b) -> [a] -> [b]
map ((SrcSpan -> SrcSpan) -> (String, SrcSpan) -> (String, SrcSpan)
forall a b. (a -> b) -> (String, a) -> (String, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SrcSpan -> SrcSpan
toRefactSrcSpan ((String, SrcSpan) -> (String, SrcSpan))
-> (((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))
    -> (String, SrcSpan))
-> ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))
-> (String, SrcSpan)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))
-> (String, SrcSpan)
forall a b. (a, b) -> a
fst) [((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))]
s
             , GenLocated SrcSpanAnnA (Pat GhcPs) -> String
forall a. Outputable a => a -> String
unsafePrettyPrint (Pat GhcPs -> GenLocated SrcSpanAnnA (Pat GhcPs)
forall a an. a -> LocatedAn an a
noLocA (Pat GhcPs -> GenLocated SrcSpanAnnA (Pat GhcPs))
-> Pat GhcPs -> GenLocated SrcSpanAnnA (Pat GhcPs)
forall a b. (a -> b) -> a -> b
$ XListPat GhcPs -> [XRec GhcPs (Pat GhcPs)] -> Pat GhcPs
forall p. XListPat p -> [LPat p] -> Pat p
ListPat XListPat GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed ((((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))
 -> GenLocated SrcSpanAnnA (Pat GhcPs))
-> [((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))]
-> [GenLocated SrcSpanAnnA (Pat GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))
-> GenLocated SrcSpanAnnA (Pat GhcPs)
forall a b. (a, b) -> b
snd [((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))]
s) :: LPat GhcPs))
          )
          (([GenLocated SrcSpanAnnA (Pat GhcPs)],
  [((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))])
 -> (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)],
     String))
-> ([(GenLocated SrcSpanAnnA (Pat GhcPs),
      ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
    -> ([GenLocated SrcSpanAnnA (Pat GhcPs)],
        [((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))]))
-> [(GenLocated SrcSpanAnnA (Pat GhcPs),
     ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
-> (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)],
    String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(GenLocated SrcSpanAnnA (Pat GhcPs),
  ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
-> ([GenLocated SrcSpanAnnA (Pat GhcPs)],
    [((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs))])
forall a b. [(a, b)] -> ([a], [b])
unzip
        )
  (Maybe
   [(GenLocated SrcSpanAnnA (Pat GhcPs),
     ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
 -> Maybe
      (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String))
-> (GenLocated SrcSpanAnnA (Pat GhcPs)
    -> Maybe
         [(GenLocated SrcSpanAnnA (Pat GhcPs),
           ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))])
-> GenLocated SrcSpanAnnA (Pat GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (Pat GhcPs), [(String, SrcSpan)], String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool
-> [String]
-> GenLocated SrcSpanAnnA (Pat GhcPs)
-> Maybe
     [(GenLocated SrcSpanAnnA (Pat GhcPs),
       ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
f Bool
True [String]
substVars
  where
    f :: Bool
-> [String]
-> GenLocated SrcSpanAnnA (Pat GhcPs)
-> Maybe
     [(GenLocated SrcSpanAnnA (Pat GhcPs),
       ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
f Bool
first [String]
_ GenLocated SrcSpanAnnA (Pat GhcPs)
x | XRec GhcPs (Pat GhcPs) -> String
patToStr XRec GhcPs (Pat GhcPs)
GenLocated SrcSpanAnnA (Pat GhcPs)
x String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"[]" = if Bool
first then Maybe
  [(GenLocated SrcSpanAnnA (Pat GhcPs),
    ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
forall a. Maybe a
Nothing else [(GenLocated SrcSpanAnnA (Pat GhcPs),
  ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
-> Maybe
     [(GenLocated SrcSpanAnnA (Pat GhcPs),
       ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
forall a. a -> Maybe a
Just []
    f Bool
first (String
ident:[String]
cs) (GenLocated SrcSpanAnnA (Pat GhcPs) -> PApp_
forall a b. View a b => a -> b
view -> PApp_ String
":" [GenLocated SrcSpanAnnA (Pat GhcPs)
a, GenLocated SrcSpanAnnA (Pat GhcPs)
b]) = ((GenLocated SrcSpanAnnA (Pat GhcPs)
a, String
-> XRec GhcPs (Pat GhcPs)
-> ((String, SrcSpan), XRec GhcPs (Pat GhcPs))
g String
ident XRec GhcPs (Pat GhcPs)
GenLocated SrcSpanAnnA (Pat GhcPs)
a) (GenLocated SrcSpanAnnA (Pat GhcPs),
 ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))
-> [(GenLocated SrcSpanAnnA (Pat GhcPs),
     ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
-> [(GenLocated SrcSpanAnnA (Pat GhcPs),
     ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
forall a. a -> [a] -> [a]
:) ([(GenLocated SrcSpanAnnA (Pat GhcPs),
   ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
 -> [(GenLocated SrcSpanAnnA (Pat GhcPs),
      ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))])
-> Maybe
     [(GenLocated SrcSpanAnnA (Pat GhcPs),
       ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
-> Maybe
     [(GenLocated SrcSpanAnnA (Pat GhcPs),
       ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool
-> [String]
-> GenLocated SrcSpanAnnA (Pat GhcPs)
-> Maybe
     [(GenLocated SrcSpanAnnA (Pat GhcPs),
       ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
f Bool
False [String]
cs GenLocated SrcSpanAnnA (Pat GhcPs)
b
    f Bool
first [String]
_ GenLocated SrcSpanAnnA (Pat GhcPs)
_ = Maybe
  [(GenLocated SrcSpanAnnA (Pat GhcPs),
    ((String, SrcSpan), GenLocated SrcSpanAnnA (Pat GhcPs)))]
forall a. Maybe a
Nothing

    g :: String -> LPat GhcPs -> ((String, SrcSpan), LPat GhcPs)
    g :: String
-> XRec GhcPs (Pat GhcPs)
-> ((String, SrcSpan), XRec GhcPs (Pat GhcPs))
g String
s (SrcSpanAnnA -> SrcSpan
forall a. SrcSpanAnn' a -> SrcSpan
locA (SrcSpanAnnA -> SrcSpan)
-> (GenLocated SrcSpanAnnA (Pat GhcPs) -> SrcSpanAnnA)
-> GenLocated SrcSpanAnnA (Pat GhcPs)
-> SrcSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (Pat GhcPs) -> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc -> SrcSpan
loc) = ((String
s, SrcSpan
loc), Pat GhcPs -> GenLocated SrcSpanAnnA (Pat GhcPs)
forall a an. a -> LocatedAn an a
noLocA (Pat GhcPs -> GenLocated SrcSpanAnnA (Pat GhcPs))
-> Pat GhcPs -> GenLocated SrcSpanAnnA (Pat GhcPs)
forall a b. (a -> b) -> a -> b
$ XVarPat GhcPs -> LIdP GhcPs -> Pat GhcPs
forall p. XVarPat p -> LIdP p -> Pat p
VarPat XVarPat GhcPs
NoExtField
noExtField (RdrName -> GenLocated SrcSpanAnnN RdrName
forall a an. a -> LocatedAn an a
noLocA (RdrName -> GenLocated SrcSpanAnnN RdrName)
-> RdrName -> GenLocated SrcSpanAnnN RdrName
forall a b. (a -> b) -> a -> b
$ FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit String
s)))

useString :: p -> LHsExpr GhcPs -> Maybe (LHsExpr GhcPs, [a], String)
useString :: forall p a.
p -> LHsExpr GhcPs -> Maybe (LHsExpr GhcPs, [a], String)
useString p
b (L SrcSpanAnnA
_ (ExplicitList XExplicitList GhcPs
_ [LHsExpr GhcPs]
xs)) | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [GenLocated SrcSpanAnnA (HsExpr GhcPs)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsExpr GhcPs]
[GenLocated SrcSpanAnnA (HsExpr GhcPs)]
xs, Just String
s <- (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Maybe Char)
-> [GenLocated SrcSpanAnnA (HsExpr GhcPs)] -> Maybe String
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM LHsExpr GhcPs -> Maybe Char
GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Maybe Char
fromChar [LHsExpr GhcPs]
[GenLocated SrcSpanAnnA (HsExpr GhcPs)]
xs =
  let literal :: LHsExpr GhcPs
literal = HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a an. a -> LocatedAn an a
noLocA (XLitE GhcPs -> HsLit GhcPs -> HsExpr GhcPs
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit XLitE GhcPs
EpAnn NoEpAnns
forall ann. EpAnn ann
EpAnnNotUsed (XHsString GhcPs -> FastString -> HsLit GhcPs
forall x. XHsString x -> FastString -> HsLit x
HsString XHsString GhcPs
SourceText
NoSourceText (String -> FastString
fsLit (String -> String
forall a. Show a => a -> String
show String
s)))) :: LHsExpr GhcPs
  in (GenLocated SrcSpanAnnA (HsExpr GhcPs), [a], String)
-> Maybe (GenLocated SrcSpanAnnA (HsExpr GhcPs), [a], String)
forall a. a -> Maybe a
Just (GenLocated SrcSpanAnnA (HsExpr GhcPs)
literal, [], GenLocated SrcSpanAnnA (HsExpr GhcPs) -> String
forall a. Outputable a => a -> String
unsafePrettyPrint GenLocated SrcSpanAnnA (HsExpr GhcPs)
literal)
useString p
_ LHsExpr GhcPs
_ = Maybe (LHsExpr GhcPs, [a], String)
Maybe (GenLocated SrcSpanAnnA (HsExpr GhcPs), [a], String)
forall a. Maybe a
Nothing

useList :: p -> LHsExpr GhcPs -> Maybe (LHsExpr GhcPs, [(String, R.SrcSpan)], String)
useList :: forall p.
p
-> LHsExpr GhcPs
-> Maybe (LHsExpr GhcPs, [(String, SrcSpan)], String)
useList p
b =
  ([(GenLocated SrcSpanAnnA (HsExpr GhcPs),
   (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
 -> (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
     String))
-> Maybe
     [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
       (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> Maybe
     (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
      String)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap  ( (\([GenLocated SrcSpanAnnA (HsExpr GhcPs)]
e, [(String, GenLocated SrcSpanAnnA (HsExpr GhcPs))]
s) ->
             (HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a an. a -> LocatedAn an a
noLocA (XExplicitList GhcPs -> [LHsExpr GhcPs] -> HsExpr GhcPs
forall p. XExplicitList p -> [LHsExpr p] -> HsExpr p
ExplicitList XExplicitList GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed [LHsExpr GhcPs]
[GenLocated SrcSpanAnnA (HsExpr GhcPs)]
e)
             , ((String, GenLocated SrcSpanAnnA (HsExpr GhcPs))
 -> (String, SrcSpan))
-> [(String, GenLocated SrcSpanAnnA (HsExpr GhcPs))]
-> [(String, SrcSpan)]
forall a b. (a -> b) -> [a] -> [b]
map ((GenLocated SrcSpanAnnA (HsExpr GhcPs) -> SrcSpan)
-> (String, GenLocated SrcSpanAnnA (HsExpr GhcPs))
-> (String, SrcSpan)
forall a b. (a -> b) -> (String, a) -> (String, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GenLocated SrcSpanAnnA (HsExpr GhcPs) -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
toSSA) [(String, GenLocated SrcSpanAnnA (HsExpr GhcPs))]
s
             , GenLocated SrcSpanAnnA (HsExpr GhcPs) -> String
forall a. Outputable a => a -> String
unsafePrettyPrint (HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a an. a -> LocatedAn an a
noLocA (HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs))
-> HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$ XExplicitList GhcPs -> [LHsExpr GhcPs] -> HsExpr GhcPs
forall p. XExplicitList p -> [LHsExpr p] -> HsExpr p
ExplicitList XExplicitList GhcPs
EpAnn AnnList
forall ann. EpAnn ann
EpAnnNotUsed (((String, GenLocated SrcSpanAnnA (HsExpr GhcPs))
 -> GenLocated SrcSpanAnnA (HsExpr GhcPs))
-> [(String, GenLocated SrcSpanAnnA (HsExpr GhcPs))]
-> [GenLocated SrcSpanAnnA (HsExpr GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map (String, GenLocated SrcSpanAnnA (HsExpr GhcPs))
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a b. (a, b) -> b
snd [(String, GenLocated SrcSpanAnnA (HsExpr GhcPs))]
s) :: LHsExpr GhcPs))
          )
          (([GenLocated SrcSpanAnnA (HsExpr GhcPs)],
  [(String, GenLocated SrcSpanAnnA (HsExpr GhcPs))])
 -> (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
     String))
-> ([(GenLocated SrcSpanAnnA (HsExpr GhcPs),
      (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
    -> ([GenLocated SrcSpanAnnA (HsExpr GhcPs)],
        [(String, GenLocated SrcSpanAnnA (HsExpr GhcPs))]))
-> [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
     (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
    String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
  (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> ([GenLocated SrcSpanAnnA (HsExpr GhcPs)],
    [(String, GenLocated SrcSpanAnnA (HsExpr GhcPs))])
forall a b. [(a, b)] -> ([a], [b])
unzip
        )
  (Maybe
   [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
     (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
 -> Maybe
      (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
       String))
-> (GenLocated SrcSpanAnnA (HsExpr GhcPs)
    -> Maybe
         [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
           (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))])
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe
     (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
      String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool
-> [String]
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe
     [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
       (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
f Bool
True [String]
substVars
  where
    f :: Bool
-> [String]
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe
     [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
       (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
f Bool
first [String]
_ GenLocated SrcSpanAnnA (HsExpr GhcPs)
x | LHsExpr GhcPs -> String
varToStr LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
x String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"[]" = if Bool
first then Maybe
  [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
    (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. Maybe a
Nothing else [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
  (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> Maybe
     [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
       (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. a -> Maybe a
Just []
    f Bool
first (String
ident:[String]
cs) (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> App2
forall a b. View a b => a -> b
view -> App2 GenLocated SrcSpanAnnA (HsExpr GhcPs)
c GenLocated SrcSpanAnnA (HsExpr GhcPs)
a GenLocated SrcSpanAnnA (HsExpr GhcPs)
b) | LHsExpr GhcPs -> String
varToStr LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
c String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
":" =
          ((GenLocated SrcSpanAnnA (HsExpr GhcPs)
a, String -> LHsExpr GhcPs -> (String, LHsExpr GhcPs)
g String
ident LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
a) (GenLocated SrcSpanAnnA (HsExpr GhcPs),
 (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))
-> [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
     (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
     (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. a -> [a] -> [a]
:) ([(GenLocated SrcSpanAnnA (HsExpr GhcPs),
   (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
 -> [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
      (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))])
-> Maybe
     [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
       (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
-> Maybe
     [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
       (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool
-> [String]
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Maybe
     [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
       (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
f Bool
False [String]
cs GenLocated SrcSpanAnnA (HsExpr GhcPs)
b
    f Bool
first [String]
_ GenLocated SrcSpanAnnA (HsExpr GhcPs)
_ = Maybe
  [(GenLocated SrcSpanAnnA (HsExpr GhcPs),
    (String, GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
forall a. Maybe a
Nothing

    g :: String -> LHsExpr GhcPs -> (String, LHsExpr GhcPs)
    g :: String -> LHsExpr GhcPs -> (String, LHsExpr GhcPs)
g String
s LHsExpr GhcPs
p = (String
s, SrcSpanAnnA
-> HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall l e. l -> e -> GenLocated l e
L (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
p) (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> HsExpr GhcPs
forall l e. GenLocated l e -> e
unLoc (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> HsExpr GhcPs)
-> GenLocated SrcSpanAnnA (HsExpr GhcPs) -> HsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ String -> LHsExpr GhcPs
strToVar String
s))

useCons :: View a App2 => Bool -> a -> Maybe (LHsExpr GhcPs, [(String, R.SrcSpan)], String)
useCons :: forall a.
View a App2 =>
Bool -> a -> Maybe (LHsExpr GhcPs, [(String, SrcSpan)], String)
useCons Bool
False (a -> App2
forall a b. View a b => a -> b
view -> App2 GenLocated SrcSpanAnnA (HsExpr GhcPs)
op GenLocated SrcSpanAnnA (HsExpr GhcPs)
x GenLocated SrcSpanAnnA (HsExpr GhcPs)
y) | LHsExpr GhcPs -> String
varToStr LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
op String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"++"
                                    , Just (LHsExpr GhcPs
newX, LHsExpr GhcPs
tplX, SrcSpan
spanX) <- LHsExpr GhcPs -> Maybe (LHsExpr GhcPs, LHsExpr GhcPs, SrcSpan)
f LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
x
                                    , Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Bool
forall a. View a App2 => a -> Bool
isAppend GenLocated SrcSpanAnnA (HsExpr GhcPs)
y =
    (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
 String)
-> Maybe
     (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
      String)
forall a. a -> Maybe a
Just (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
gen LHsExpr GhcPs
newX LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
y
         , [(String
"x", SrcSpan
spanX), (String
"xs", GenLocated SrcSpanAnnA (HsExpr GhcPs) -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
toSSA GenLocated SrcSpanAnnA (HsExpr GhcPs)
y)]
         , LHsExpr GhcPs -> String
forall a. Outputable a => a -> String
unsafePrettyPrint (LHsExpr GhcPs -> String) -> LHsExpr GhcPs -> String
forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
gen LHsExpr GhcPs
tplX (String -> LHsExpr GhcPs
strToVar String
"xs")
         )
  where
    f :: LHsExpr GhcPs -> Maybe (LHsExpr GhcPs, LHsExpr GhcPs, R.SrcSpan)
    f :: LHsExpr GhcPs -> Maybe (LHsExpr GhcPs, LHsExpr GhcPs, SrcSpan)
f (L SrcSpanAnnA
_ (ExplicitList XExplicitList GhcPs
_ [LHsExpr GhcPs
x]))
      | GenLocated SrcSpanAnnA (HsExpr GhcPs) -> Bool
forall a. Brackets a => a -> Bool
isAtom LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
x Bool -> Bool -> Bool
|| LHsExpr GhcPs -> Bool
isApp LHsExpr GhcPs
x = (GenLocated SrcSpanAnnA (HsExpr GhcPs),
 GenLocated SrcSpanAnnA (HsExpr GhcPs), SrcSpan)
-> Maybe
     (GenLocated SrcSpanAnnA (HsExpr GhcPs),
      GenLocated SrcSpanAnnA (HsExpr GhcPs), SrcSpan)
forall a. a -> Maybe a
Just (LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
x, String -> LHsExpr GhcPs
strToVar String
"x", GenLocated SrcSpanAnnA (HsExpr GhcPs) -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
toSSA LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
x)
      | Bool
otherwise = (GenLocated SrcSpanAnnA (HsExpr GhcPs),
 GenLocated SrcSpanAnnA (HsExpr GhcPs), SrcSpan)
-> Maybe
     (GenLocated SrcSpanAnnA (HsExpr GhcPs),
      GenLocated SrcSpanAnnA (HsExpr GhcPs), SrcSpan)
forall a. a -> Maybe a
Just (GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a. Brackets a => a -> a
addParen LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
x, GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a. Brackets a => a -> a
addParen (String -> LHsExpr GhcPs
strToVar String
"x"), GenLocated SrcSpanAnnA (HsExpr GhcPs) -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
toSSA LHsExpr GhcPs
GenLocated SrcSpanAnnA (HsExpr GhcPs)
x)
    f LHsExpr GhcPs
_ = Maybe (LHsExpr GhcPs, LHsExpr GhcPs, SrcSpan)
Maybe
  (GenLocated SrcSpanAnnA (HsExpr GhcPs),
   GenLocated SrcSpanAnnA (HsExpr GhcPs), SrcSpan)
forall a. Maybe a
Nothing

    gen :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
    gen :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
gen LHsExpr GhcPs
x = HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a an. a -> LocatedAn an a
noLocA (HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs))
-> (GenLocated SrcSpanAnnA (HsExpr GhcPs) -> HsExpr GhcPs)
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XOpApp GhcPs
-> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
forall p.
XOpApp p -> LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p
OpApp XOpApp GhcPs
EpAnn [AddEpAnn]
forall ann. EpAnn ann
EpAnnNotUsed LHsExpr GhcPs
x (HsExpr GhcPs -> GenLocated SrcSpanAnnA (HsExpr GhcPs)
forall a an. a -> LocatedAn an a
noLocA (XVar GhcPs -> LIdP GhcPs -> HsExpr GhcPs
forall p. XVar p -> LIdP p -> HsExpr p
HsVar XVar GhcPs
NoExtField
noExtField  (RdrName -> GenLocated SrcSpanAnnN RdrName
forall a an. a -> LocatedAn an a
noLocA RdrName
consDataCon_RDR)))
useCons Bool
_ a
_ = Maybe (LHsExpr GhcPs, [(String, SrcSpan)], String)
Maybe
  (GenLocated SrcSpanAnnA (HsExpr GhcPs), [(String, SrcSpan)],
   String)
forall a. Maybe a
Nothing

typeListChar :: LHsType GhcPs
typeListChar :: LHsType GhcPs
typeListChar =
  HsType GhcPs -> LocatedAn AnnListItem (HsType GhcPs)
forall a an. a -> LocatedAn an a
noLocA (HsType GhcPs -> LocatedAn AnnListItem (HsType GhcPs))
-> HsType GhcPs -> LocatedAn AnnListItem (HsType GhcPs)
forall a b. (a -> b) -> a -> b
$ XListTy GhcPs -> LHsType GhcPs -> HsType GhcPs
forall pass. XListTy pass -> LHsType pass -> HsType pass
HsListTy XListTy GhcPs
EpAnn AnnParen
forall ann. EpAnn ann
EpAnnNotUsed
    (HsType GhcPs -> LocatedAn AnnListItem (HsType GhcPs)
forall a an. a -> LocatedAn an a
noLocA (XTyVar GhcPs -> PromotionFlag -> LIdP GhcPs -> HsType GhcPs
forall pass.
XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
HsTyVar XTyVar GhcPs
EpAnn [AddEpAnn]
forall ann. EpAnn ann
EpAnnNotUsed PromotionFlag
NotPromoted (RdrName -> GenLocated SrcSpanAnnN RdrName
forall a an. a -> LocatedAn an a
noLocA (FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit String
"Char")))))

typeString :: LHsType GhcPs
typeString :: LHsType GhcPs
typeString =
  HsType GhcPs -> LocatedAn AnnListItem (HsType GhcPs)
forall a an. a -> LocatedAn an a
noLocA (HsType GhcPs -> LocatedAn AnnListItem (HsType GhcPs))
-> HsType GhcPs -> LocatedAn AnnListItem (HsType GhcPs)
forall a b. (a -> b) -> a -> b
$ XTyVar GhcPs -> PromotionFlag -> LIdP GhcPs -> HsType GhcPs
forall pass.
XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
HsTyVar XTyVar GhcPs
EpAnn [AddEpAnn]
forall ann. EpAnn ann
EpAnnNotUsed PromotionFlag
NotPromoted (RdrName -> GenLocated SrcSpanAnnN RdrName
forall a an. a -> LocatedAn an a
noLocA (FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit String
"String")))

stringType :: LHsDecl GhcPs  -> [Idea]
stringType :: LHsDecl GhcPs -> [Idea]
stringType (L SrcSpanAnnA
_ HsDecl GhcPs
x) = case HsDecl GhcPs
x of
  InstD XInstD GhcPs
_ ClsInstD{
    cid_inst :: forall pass. InstDecl pass -> ClsInstDecl pass
cid_inst=
        ClsInstDecl{cid_binds :: forall pass. ClsInstDecl pass -> LHsBinds pass
cid_binds=LHsBinds GhcPs
x, cid_tyfam_insts :: forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts=[LTyFamInstDecl GhcPs]
y, cid_datafam_insts :: forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts=[LDataFamInstDecl GhcPs]
z}} ->
    Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs)) -> [Idea]
forall {from}. Data from => from -> [Idea]
f LHsBinds GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
x [Idea] -> [Idea] -> [Idea]
forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)] -> [Idea]
forall {from}. Data from => from -> [Idea]
f [LTyFamInstDecl GhcPs]
[GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)]
y [Idea] -> [Idea] -> [Idea]
forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (DataFamInstDecl GhcPs)] -> [Idea]
forall {from}. Data from => from -> [Idea]
f [LDataFamInstDecl GhcPs]
[GenLocated SrcSpanAnnA (DataFamInstDecl GhcPs)]
z -- Pretty much everything but the instance type.
  HsDecl GhcPs
_ -> HsDecl GhcPs -> [Idea]
forall {from}. Data from => from -> [Idea]
f HsDecl GhcPs
x
  where
    f :: from -> [Idea]
f from
x = (LocatedAn AnnListItem (HsType GhcPs) -> [Idea])
-> [LocatedAn AnnListItem (HsType GhcPs)] -> [Idea]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap LHsType GhcPs -> [Idea]
LocatedAn AnnListItem (HsType GhcPs) -> [Idea]
g ([LocatedAn AnnListItem (HsType GhcPs)] -> [Idea])
-> [LocatedAn AnnListItem (HsType GhcPs)] -> [Idea]
forall a b. (a -> b) -> a -> b
$ from -> [LocatedAn AnnListItem (HsType GhcPs)]
forall from to. Biplate from to => from -> [to]
childrenBi from
x

    g :: LHsType GhcPs -> [Idea]
    g :: LHsType GhcPs -> [Idea]
g e :: LHsType GhcPs
e@(LHsType GhcPs -> LHsType GhcPs
fromTyParen -> LHsType GhcPs
x) = [String
-> Located (HsType GhcPs)
-> Located (HsType GhcPs)
-> [Refactoring SrcSpan]
-> Idea
forall a.
Outputable a =>
String -> Located a -> Located a -> [Refactoring SrcSpan] -> Idea
ignore String
"Use String" (LocatedAn AnnListItem (HsType GhcPs) -> Located (HsType GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc LHsType GhcPs
LocatedAn AnnListItem (HsType GhcPs)
x) (LocatedAn AnnListItem (HsType GhcPs) -> Located (HsType GhcPs)
forall a e. LocatedAn a e -> Located e
reLoc ((LocatedAn AnnListItem (HsType GhcPs)
 -> LocatedAn AnnListItem (HsType GhcPs))
-> LocatedAn AnnListItem (HsType GhcPs)
-> LocatedAn AnnListItem (HsType GhcPs)
forall on. Uniplate on => (on -> on) -> on -> on
transform LocatedAn AnnListItem (HsType GhcPs)
-> LocatedAn AnnListItem (HsType GhcPs)
f LHsType GhcPs
LocatedAn AnnListItem (HsType GhcPs)
x))
                              [Refactoring SrcSpan]
rs | Bool -> Bool
not (Bool -> Bool)
-> ([Refactoring SrcSpan] -> Bool) -> [Refactoring SrcSpan] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Refactoring SrcSpan] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Refactoring SrcSpan] -> Bool) -> [Refactoring SrcSpan] -> Bool
forall a b. (a -> b) -> a -> b
$ [Refactoring SrcSpan]
rs]
      where f :: LocatedAn AnnListItem (HsType GhcPs) -> LHsType GhcPs
f LocatedAn AnnListItem (HsType GhcPs)
x = if LocatedAn AnnListItem (HsType GhcPs)
-> LocatedAn AnnListItem (HsType GhcPs) -> Bool
forall a. Data a => a -> a -> Bool
astEq LocatedAn AnnListItem (HsType GhcPs)
x LHsType GhcPs
LocatedAn AnnListItem (HsType GhcPs)
typeListChar then LHsType GhcPs
typeString else LHsType GhcPs
LocatedAn AnnListItem (HsType GhcPs)
x
            rs :: [Refactoring SrcSpan]
rs = [RType
-> SrcSpan -> [(String, SrcSpan)] -> String -> Refactoring SrcSpan
forall a. RType -> a -> [(String, a)] -> String -> Refactoring a
Replace RType
Type (LocatedAn AnnListItem (HsType GhcPs) -> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
toSSA LocatedAn AnnListItem (HsType GhcPs)
t) [] (LocatedAn AnnListItem (HsType GhcPs) -> String
forall a. Outputable a => a -> String
unsafePrettyPrint LHsType GhcPs
LocatedAn AnnListItem (HsType GhcPs)
typeString) | LocatedAn AnnListItem (HsType GhcPs)
t <- LocatedAn AnnListItem (HsType GhcPs)
-> [LocatedAn AnnListItem (HsType GhcPs)]
forall on. Uniplate on => on -> [on]
universe LHsType GhcPs
LocatedAn AnnListItem (HsType GhcPs)
x, LocatedAn AnnListItem (HsType GhcPs)
-> LocatedAn AnnListItem (HsType GhcPs) -> Bool
forall a. Data a => a -> a -> Bool
astEq LocatedAn AnnListItem (HsType GhcPs)
t LHsType GhcPs
LocatedAn AnnListItem (HsType GhcPs)
typeListChar]