The immediate style in the Haskell template

Consider the following Haskell template function:

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

Is it possible to exclude a lambda expression from the right side of the equation and write composeQ using a dot style?

+4
source share
1 answer

There is no general way to merge expressions into any point-free quote, but this particular case can be implemented as follows:

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

Here was a flip infixApp , which usually takes parameters in the order left op right to op left right , and then provides it with a composition operator. Now we have a point-free function equivalent to the original composeQ .

+4
source

Source: https://habr.com/ru/post/1398171/


All Articles