元组函数的N元版本 [英] N-Ary Versions of Tuple Functions
本文介绍了元组函数的N元版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个具有元组函数的n元版本的库,如 first
, ***
等,通过模板Haskell(或使用其他方法)。
理想情况下,我想能够说:
$(select 3 [0,1])$ b $ b
使lambda
\(x,y,z) - > (x,y)
以及通用 ***
for function
$(tapply 3 [(0,f),(1,g)) ,(2,h)])
这会使lambda
\fgh(x,y,z) - > (fx,gy,hz)
其他n元函数也很好,但那些是我目前需要两个。 nofollow>一个例子来实现这个使用模板哈斯克尔。
Is there a library that has n-ary versions of tuple functions like first
, ***
, etc, through Template Haskell (or using some other method).
Ideally I would like to able to say
$(select 3 [0, 1])
which we make the lambda
\(x, y, z) -> (x, y)
and for a generic ***
for functions
$(tapply 3 [(0, "f"), (1, "g"), (2, "h")])
which would make the lambda
\f g h (x, y, z) -> (f x, g y, h z)
Other n-ary functions would also be nice, but those are the two I need currently.
解决方案
Here is an example to achieve this using Template Haskell.
这篇关于元组函数的N元版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文