# haskell - are tuples defined recursively? [closed]

1. Are n-tuples defined recursively in terms of 2-tuples, for example, are (a,b,c) and (a,(b,c)) the same?

2. If not, what's the rationale behind it?

(a, (b, c)) is a 2-tuple whose second element happens to be another 2-tuple. If your suggestion had been adopted, it would not be possible to represent a tuple inside the final cell of another tuple. Which would be a bizarrely asymmetric restriction and make tuples much less generally useful.

• I am now confused. As lists are defined recursively in haskell, then it will not be possible to represent a list inside the final cell of another list?! I know that a:[b,c] and [a,b,c] are the same, but how about [a,[b,c]]? Mar 1, 2015 at 13:24
• Lists are defined recursively but not the way you think. Firstly, you cannot have [a,[b,c]]. In Haskell lists, each element has to bee of the same type. You can have a list of lists - [[a,b],[c,d,e],[]] - but not a list mixing non-lists and lists. When you create List a, every element in the list has to be of type a. Mar 1, 2015 at 14:04
• Haskell lists are an Algebraic Data Type. The definition is data List a = Nil | Cons a (List a). The recursion is in the definition, which defines List in terms of itself. Nil and Cons a are both constructors for List a. Nil gives an empty list while Cons a (List a) prepends an element of type a onto an existing List a. So [1,2,3] is actually Cons 1 (Cons 2 (Cons 3 Nil)). Mar 1, 2015 at 14:14
• This is answer is simply a misunderstanding. With a slight variation to the posters example it is possible to represent every size of tuple using only 2-tuples. In Ceylon for example tuples are represented in such a way.
– Lii
Nov 20, 2022 at 17:41

1, No it's defined separately for each tuple. (So data (,) a b = (,) a b for the 2-tuple). You can see the full list(and limit that you can use) here: https://downloads.haskell.org/~ghc/7.4.1/docs/html/libraries/ghc-prim-0.2.0.0/GHC-Tuple.html (also the comment about the number of n-tuples in the source is funny)