N-Ary Versions of Tuple Functions
Is there a library that has n-ary versions of tuple func开发者_运维百科tions 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.
The tuple library provides lots of these sorts of functions.
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. (That link could be more up to date... if in doubt, and you don't have especially high performance requirements, just use SYB)
精彩评论