4

Consider the following Template Haskell function:

composeQ :: ExpQ -> ExpQ -> ExpQ
composeQ = \x y -> [| $(x) . $(y) |]

Is it possible to eliminate the lambda expression from the right hand side of the equation and write composeQ using point-free style?

1 Answers1

4

There's no generic way to splice expressions into any quotation in point-free style, but this particular case could be implemented like this:

composeQ :: ExpQ -> ExpQ -> ExpQ
composeQ = flip infixApp [|(.)|]

Here were flip infixApp which usually takes parameters in the order left op right into op left right and then supply it with the composition operator. Now we have a point-free function that's equivalent to the original composeQ.

shang
  • 24,642
  • 3
  • 58
  • 86