From 3c8288e53347b90968abe5afcb1addf3bea5e00e Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 7 Mar 2024 05:19:24 +0100 Subject: chore: simplify quasi quoter implementation --- src/Process/Shell.hs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/Process') diff --git a/src/Process/Shell.hs b/src/Process/Shell.hs index 2d254ad..10b85b5 100644 --- a/src/Process/Shell.hs +++ b/src/Process/Shell.hs @@ -144,12 +144,8 @@ sh = QuasiQuoter quoteExp undefined undefined undefined Lit <$> takeWhile1P Nothing ((&&) <$> (/= '#') <*> (/= '\'')) ] - makeExp :: [Expr] -> Q Exp - makeExp exprs = do - appE [|sh_|] $ flip (foldM (flip go)) exprs =<< [|""|] - - go (Lit s) = appE [|flip (++) s|] . pure - go (Var q exp) = - appE - (appE [|flip (++)|] (appE [|if q then squote else dquote|] exp)) - . pure + makeExp exprs = + [|sh_ $(foldr (\a b -> [|$a ++ $b|]) [|""|] (map toExp exprs))|] + + toExp (Lit s) = [|s|] + toExp (Var q exp) = [|(if q then squote else dquote) $exp|] -- cgit v1.2.3