Could this be improved using template haskell quasi-quotes/splices/etc without changing the type?

predFuse :: Exp -> Exp -> Exp
predFuse p' q' = let
x = mkName "x"
p = mkName "p"
q = mkName "q"
l = LamE [VarP p,VarP q,VarP x] (InfixE (Just (AppE (VarE p) (VarE x))) (VarE '(&&)) (Just (AppE (VarE q) (VarE x))))
in AppE (AppE l p') q'

Follow

Hints:

λ> runQ [| \p q x -> p x && q x |]
LamE [VarP p_0,VarP q_1,VarP x_2] (InfixE (Just (AppE (VarE p_0) (VarE x_2))) (VarE GHC.Classes.&&) (Just (AppE (VarE q_1) (VarE x_2))))

λ> :t runQ [| \p q x -> p x && q x |]
runQ [| \p q x -> p x && q x |]
:: Language.Haskell.TH.Syntax.Quasi m => m Exp

Sign in to participate in the conversation
Kernel.org social

Kernel.org after-party social