Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is (,) defined internally?

Tags:

haskell

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.

like image 663
Mike Izbicki Avatar asked Aug 10 '12 21:08

Mike Izbicki


1 Answers

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.

like image 103
Cat Plus Plus Avatar answered Sep 16 '22 20:09

Cat Plus Plus