简体   繁体   English

元组函数的N-Ary版本

[英]N-Ary Versions of Tuple Functions

Is there a library that has n-ary versions of tuple functions like first , *** , etc, through Template Haskell (or using some other method). 是否有一个通过Template Haskell(或使用其他方法)具有n元版本的元组函数(如first***等)的库。

Ideally I would like to able to say 理想情况下,我想说

$(select 3 [0, 1])

which we make the lambda 我们做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 这将使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. 其他n元函数也不错,但是那是我目前需要的两个。

这是使用Template Haskell实现此目的的示例

元组库提供了许多这类功能。

Generally, I'd say you want to use a proper ADT instead, and libraries like bifunctor , or, if it gets more complex than that, a proper generics library. 通常,我想说的是,您想使用适当的ADT和像bifunctor这样的 ,或者,如果比这更复杂,则使用适当的泛型库。 (That link could be more up to date... if in doubt, and you don't have especially high performance requirements, just use SYB ) (该链接可能是最新的……如果有疑问,并且您对性能没有特别高的要求,请使用SYB

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

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