It's trivial to redefine the function
(,) :: a -> b -> (a,b)
(,) a b = (a,b)
The weird (to me) thing is that this function is defined for arbitrary length tuples. So, for example, there is actually a function:
(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) :: a -> b -> c -> ... -> (a,b,c,...)
How is this done? Why isn't it done for all the standard functions on tuples, like zip?
Hoogle gives me no results, and I don't see how template Haskell could do this, so I assume it must be some sort of magic inside the compiler. But that seems very un-Haskelly to me.
How is this done?
Compiler support. Haskell language report mandates (,)
to be supported for at least up to 15 arguments (6.1.4), but GHC goes a bit further and generates them for a lot more (last time we've tested this, it could handle hundreds or even thousands). zip
and other tuple functions have to be defined for up to 7-tuples. I don't know if GHC generates those for larger amounts.
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