简体   繁体   English

模板Haskell中的无点样式

[英]Point-free style in Template Haskell

Consider the following Template Haskell function: 考虑以下Template Haskell函数:

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? 是否有可能从等式的右边消除lambda表达式并使用无点样式编写composeQ

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. 这里是翻转infixApp ,它通常将left op right参数left op right参数带入op left right ,然后使用合成运算符提供它。 Now we have a point-free function that's equivalent to the original composeQ . 现在我们有一个无点函数,相当于原始的composeQ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM