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.

|improve this answer|||||
  • 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]]? – Michael Tsang Mar 1 '15 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. – itsbruce Mar 1 '15 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)). – itsbruce Mar 1 '15 at 14:14

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- (also the comment about the number of n-tuples in the source is funny)

2, I would say performance but not sure about this.(Edit: see @itsbruce's answer for a better reason)

|improve this answer|||||
  • 1
    would you mind explaining more on what this resource does and why do you recommend it as answering the question asked? "Link-only answers" are not quite welcome at Stack Exchange – gnat Jan 26 '15 at 15:09
  • 1
    I've added a an example from the link but I don't think that copying stuff over here helps in this case. – erdeszt Jan 26 '15 at 17:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.