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?
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.