2

Howcome I can't make a 16-tuple in Haskell, and what does this error mean?

GHCi, version 7.6.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)

<interactive>:2:1:
    No instance for (Show
                       (t0,
                        t1,
                        t2,
                        t3,
                        t4,
                        t5,
                        t6,
                        t7,
                        t8,
                        t9,
                        t10,
                        t11,
                        t12,
                        t13,
                        t14,
                        t15))
      arising from a use of `print'
    Possible fix:
      add an instance declaration for
      (Show
         (t0,
          t1,
          t2,
          t3,
          t4,
          t5,
          t6,
          t7,
          t8,
          t9,
          t10,
          t11,
          t12,
          t13,
          t14,
          t15))
    In a stmt of an interactive GHCi command: print it

<interactive>:2:2:
    No instance for (Num t0) arising from the literal `1'
    The type variable `t0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 1
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:4:
    No instance for (Num t1) arising from the literal `2'
    The type variable `t1' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 2
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:6:
    No instance for (Num t2) arising from the literal `3'
    The type variable `t2' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 3
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:8:
    No instance for (Num t3) arising from the literal `4'
    The type variable `t3' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 4
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:10:
    No instance for (Num t4) arising from the literal `5'
    The type variable `t4' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 5
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:12:
    No instance for (Num t5) arising from the literal `6'
    The type variable `t5' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 6
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:14:
    No instance for (Num t6) arising from the literal `7'
    The type variable `t6' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 7
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:16:
    No instance for (Num t7) arising from the literal `8'
    The type variable `t7' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 8
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:18:
    No instance for (Num t8) arising from the literal `9'
    The type variable `t8' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 9
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:20:
    No instance for (Num t9) arising from the literal `10'
    The type variable `t9' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 10
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:23:
    No instance for (Num t10) arising from the literal `11'
    The type variable `t10' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 11
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:26:
    No instance for (Num t11) arising from the literal `12'
    The type variable `t11' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 12
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:29:
    No instance for (Num t12) arising from the literal `13'
    The type variable `t12' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 13
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:32:
    No instance for (Num t13) arising from the literal `14'
    The type variable `t13' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 14
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:35:
    No instance for (Num t14) arising from the literal `15'
    The type variable `t14' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 15
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

<interactive>:2:38:
    No instance for (Num t15) arising from the literal `16'
    The type variable `t15' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Num Double -- Defined in `GHC.Float'
      instance Num Float -- Defined in `GHC.Float'
      instance Integral a => Num (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus three others
    In the expression: 16
    In the expression:
      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
    In an equation for `it':
        it = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
Prelude> 
hammar
  • 138,522
  • 17
  • 304
  • 385
Dog
  • 7,707
  • 8
  • 40
  • 74
  • Similar question asked here: http://stackoverflow.com/questions/15559234/working-with-list-of-tuples-in-haskell/15559825 – kputnam Mar 29 '13 at 02:48
  • Duplicate of http://stackoverflow.com/q/2978389/676939 – Alexandros Mar 29 '13 at 11:14
  • @Alexandros: This isn't duplicate, I'm asking what the 16 errors mean, which the "answer" here didn't answer. – Dog Apr 01 '13 at 16:40

1 Answers1

13

The base libary includes show instances only for tuples up to size 15. In general it is not a good idea to use very large tuples.

Twan van Laarhoven
  • 2,542
  • 15
  • 16
  • Okay, but the second half of the question remains unanswered. – Dog Mar 28 '13 at 17:57
  • 2
    1) You can make 16 tuples in Haskell (you just did) and 2) the error means there is no routine to transform a 16 tuple to a string in the Prelude but you can feel free to make your own `instance Show ...`. – Thomas M. DuBuisson Mar 28 '13 at 18:04
  • @ThomasM.DuBuisson But why are there 16 more errors after that? – Dog Mar 28 '13 at 18:08
  • 1
    @Dog: try entering `(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) :: (Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int)`. It's the monomorphism restriction acting up again! – yatima2975 Mar 28 '13 at 18:34
  • 2
    @yatima2975 But a) it shouldn't, there are only nice constraints and the types should be defaulted to `Integer`, b) that behaviour is new in 7.6, previous versions gave only the missing `Show` instance. – Daniel Fischer Mar 28 '13 at 18:56
  • 1
    @DanielFischer: Hmm, you're right. Truth be told, I never felt the need to make 16-tuples before now. – yatima2975 Mar 28 '13 at 19:14
  • 1
    @yatima2975 Yes, investigating the limits is pretty much the only reason to use 16-tuples. – Daniel Fischer Mar 28 '13 at 19:20
  • 1
    @Daniel Fischer: Type defaulting isn't happening because without the `Show` instance there to guide it to the simpler types it is trying to find a `Show (a,b,c,d,e,f,...)` still. With `instance (Show a,Show b, Show c, ...) => Show (a,b,c, ...)`, that instance head would resolve and you'd get new separate constraints `Show a`, `Show b`, `Show c`, which then get defaulted to `Integer` by the combination of `Num` and `Show` and the standard defaulting dispatch, but it died before it got there. Ultimately, it just comes down to the fact that there is no notion of code polymorphic over tuple arity – Edward Kmett Mar 29 '13 at 07:42
  • @EdwardKmett Without the `Show` constraint from `instance (Show a, ...) => Show (a,...)`, there is a sole `Num` constraint from the literal. That is defaultable, and per my understanding should be defaulted. Of course, in the presence of a type error (No instance Show ...), it doesn't really matter. – Daniel Fischer Mar 29 '13 at 11:56