Ticket #2358 (closed merge: fixed)

Opened 6 months ago

Last modified 2 months ago

Template Haskell's TupleT considers unary tuples as a valid types.

Reported by: fons Assigned to:
Priority: normal Milestone: 6.8 branch
Component: Template Haskell Version: 6.8.2
Severity: normal Keywords:
Cc: Difficulty: Unknown
Test Case: TH_1tuple Operating System: Unknown/Multiple
Architecture: Unknown/Multiple

Description

I don't know how tuples are internally implemented in GHC, but the Haskell report (3.8) specifically establishes two as their lower size bound.

When provided a zero (or null list) arguments, all TupleT, TupP and TupE behave like the unit type (which is certainly reasonable). However, they handle argument 1 (or the singleton list) in different ways:

  • TupleP [pat] is equivalent to pat (which again, is perfectly reasonable)
  • TupE [exp] behaves as exp (again, it seems right)

However:

  • TupleT 1 `AppT` VarT ''Int is a different type than VarT ''Int

See the following two examples:

  1. tupE [exp] behaves as expected:
Prelude Language.Haskell.TH> $(sigE (tupE [[|1|]]) (conT ''Int))
1
  1. tupleT 1 doesn't:
Prelude Language.Haskell.TH> $(sigE [|1|] (tupleT 1 `appT` conT ''Int))

<interactive>:1:2:
    No instance for (Num (Int))
      arising from the literal `1' at <interactive>:1:2-40
    Possible fix: add an instance declaration for (Num (Int))
    In the expression: $(sigE [| 1 |] (tupleT 1 `appT` conT 'Int))
    In the definition of `it':
        it = $(sigE [| 1 |] (tupleT 1 `appT` conT 'Int))

Probably, since unary tuples are not legal, the typechecker should simply raise an error when TupleT is found to have received 1 as argument.

Change History

06/30/08 00:43:06 changed by simonpj

  • testcase set to TH_1tuple.
  • difficulty set to Unknown.
  • type changed from bug to merge.
  • owner set to igloo.

Fixed by

Sat Jun 14 13:39:39 BST 2008  simonpj@microsoft.com
  * Fix Trac #2358: 1-tuples in Template Haskell

Queue for merging to the branch, in the event of 6.8.4

Simon

07/01/08 18:21:18 changed by igloo

  • milestone set to 6.8 branch.

07/03/08 09:21:21 changed by igloo

  • owner deleted.

09/30/08 08:37:34 changed by simonmar

  • architecture changed from Unknown to Unknown/Multiple.

09/30/08 08:51:51 changed by simonmar

  • os changed from Unknown to Unknown/Multiple.

10/03/08 14:18:20 changed by igloo

  • status changed from new to closed.
  • resolution set to fixed.

We won't be releasing 6.8.4.