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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With