Template Haskell: unboxedTupleTypeName doesn't handle unboxed 0- and 1-tuples
GHC has a notion of unboxed 0-tuples and 1-tuples:
λ> :set -XUnboxedTuples
λ> :k (##)
(##) :: TYPE 'GHC.Types.VoidRep
λ> :k (# Int #)
(# Int #) :: TYPE 'GHC.Types.UnboxedTupleRep
But it is impossible to acquire the Names of these type constructors using unboxedTupleTypeName from template-haskell:
λ> :set -XTemplateHaskell
λ> :m + Language.Haskell.TH Language.Haskell.TH.Syntax
λ> :k $(conT (unboxedTupleTypeName 0))
<interactive>:1:1: error:
• Exception when trying to run compile-time code:
unboxedTupleTypeName 0
CallStack (from HasCallStack):
error, called at libraries/template-haskell/Language/Haskell/TH/Syntax.hs:1179:26 in template-haskell:Language.Haskell.TH.Syntax
Code: conT (unboxedTupleTypeName 0)
• In the untyped splice: $(conT (unboxedTupleTypeName 0))
λ> :k $(conT (unboxedTupleTypeName 1))
<interactive>:1:1: error:
• Exception when trying to run compile-time code:
unboxedTupleTypeName 1
CallStack (from HasCallStack):
error, called at libraries/template-haskell/Language/Haskell/TH/Syntax.hs:1180:26 in template-haskell:Language.Haskell.TH.Syntax
Code: conT (unboxedTupleTypeName 1)
• In the untyped splice: $(conT (unboxedTupleTypeName 1))
And similarly for unboxedTupleDataName.
This is because of silly restrictions put in place on the definitions of unboxedTupleTypeName and unboxedTupleDataName within template-haskell:
-- Unboxed tuple data and type constructors
-- | Unboxed tuple data constructor
unboxedTupleDataName :: Int -> Name
-- | Unboxed tuple type constructor
unboxedTupleTypeName :: Int -> Name
unboxedTupleDataName 0 = error "unboxedTupleDataName 0"
unboxedTupleDataName 1 = error "unboxedTupleDataName 1"
unboxedTupleDataName n = mk_unboxed_tup_name (n-1) DataName
unboxedTupleTypeName 0 = error "unboxedTupleTypeName 0"
unboxedTupleTypeName 1 = error "unboxedTupleTypeName 1"
unboxedTupleTypeName n = mk_unboxed_tup_name (n-1) TcClsName
It should be possible to lift this restriction. I'll work on this.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Template Haskell |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |